Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidyups to help run Ruby example #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ example-server-ruby: server/server
$(CURDIR)/server/server $(CURDIR)/examples/server ~/.rbenv/versions/2.4.1/bin/ruby $(CURDIR)/examples/client/ruby/harness.rb

example-client: client/client
cd $(CURDIR)/examples/client && rm -rf work && ../../client/client 127.0.0.1:8000
cd $(CURDIR)/examples/client && rm -rf work && ../../client/client 127.0.0.1:1234

example-client-ruby-build:
cd $(CURDIR)/examples/client/ruby && bundle install

# Debug pretty printer
print-%: ; @echo $*=$($*)
Expand Down
6 changes: 6 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (f Fuzzer) run() error {

func (f AFLFuzzCommand) cmd() *exec.Cmd {
fullCommandArgs := append([]string{
// Memory and timeout limits need to be really high in order to
// cope with slow slow Ruby targets.
//
// TODO(rob): make these configurable
"-m", "100000",
"-t", "100000",
"-o", "output",
"-i", "input"}, f.targetCommand...)
c := exec.Command(aflPath(), fullCommandArgs...)
Expand Down
2 changes: 1 addition & 1 deletion examples/client/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://intgems.local.corp.stripe.com:446/
specs:
afl (0.0.1)
afl (0.0.2)

PLATFORMS
ruby
Expand Down
8 changes: 5 additions & 3 deletions examples/client/ruby/harness.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
$: << "../lib"
require 'rubygems'
require 'bundler/setup'

require 'afl'

def byte
$stdin.read(1)
end
Expand All @@ -19,8 +23,6 @@ def h
raise "Crashed"
end

require 'afl'

unless ENV['NO_AFL']
AFL.init
end
Expand Down
10 changes: 8 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -142,7 +144,7 @@ func getInputs(c web.C, w http.ResponseWriter, r *http.Request) {
encoder.Encode(corpus)
}

func setupAndServe() {
func setupAndServe(port int) {
// Browser endpoints
goji.Get("/", index)
// Client endpoints
Expand All @@ -151,6 +153,8 @@ func setupAndServe() {
goji.Get("/target/meta", getTargetMeta)
goji.Get("/target/binary", getTargetBinary)
goji.Get("/inputs", getInputs)

flag.Set("bind", fmt.Sprintf(":%d", port))
goji.Serve()
}

Expand Down Expand Up @@ -215,5 +219,7 @@ func main() {
reaper := newReaper(nodes, 1*time.Hour)
go reaper.run()

setupAndServe()
port := 1234
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this stray? Is there some weird scoping thing I don't understand?

Copy link
Collaborator Author

@robert robert Aug 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have been clearer - I wanted to make it easier to change the server port, since 8000 (goji's default) is often already in use by other programs. One day this var will become a config or command line value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I just meant I think this shadows the port argument to this function? but maybe I'm confused.


setupAndServe(port)
}