Skip to content

Commit

Permalink
[Go] remove "-lpthread" flag from "compile_fuzzer" and fix comments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor1s committed Apr 16, 2020
1 parent b8114c3 commit b881b6a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 45 deletions.
6 changes: 3 additions & 3 deletions docs/getting-started/new-project-guide/go_lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ function compile_fuzzer {
function=$2
fuzzer=$3
# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func $function -o $fuzzer.a $path
# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}
compile_fuzzer ./pkg/compiler Fuzz compiler_fuzzer
Expand Down
19 changes: 11 additions & 8 deletions projects/go-attestation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
#
################################################################################

# Based on the function from oss-fuzz/projects/golang/build.sh script.
function compile_fuzzer {
package=$1
function=$2
fuzzer=$3

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func $function -o $fuzzer.a $package

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}

compile_fuzzer github.com/google/go-attestation/attest FuzzParseEventLog parse_event_log_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic12 parse_ak_public12_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic20 parse_ak_public20_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseEKCertificate parse_ek_certificate_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseEventLog \
parse_event_log_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic12 \
parse_ak_public12_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic20 \
parse_ak_public20_fuzzer
compile_fuzzer github.com/google/go-attestation/attest FuzzParseEKCertificate \
parse_ek_certificate_fuzzer
9 changes: 4 additions & 5 deletions projects/go-dns/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
#
################################################################################

# build target function
function compile_fuzzer {
path=$1
function=$2
fuzzer=$3

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -tags fuzz -func $function -o $fuzzer.a $path

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}

#same as usual except for added -tags fuzz
# Same as usual except for added -tags fuzz.
compile_fuzzer /root/go/src/github.com/miekg/dns/ FuzzNewRR fuzz_newrr
compile_fuzzer /root/go/src/github.com/miekg/dns/ Fuzz fuzz_msg_unpack
7 changes: 3 additions & 4 deletions projects/go-json-iterator/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
#
################################################################################

# build target function
function compile_fuzzer {
path=$1
function=$2
fuzzer=$3

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func $function -o $fuzzer.a $path

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}

compile_fuzzer . Fuzz fuzz_json
24 changes: 12 additions & 12 deletions projects/golang/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
# limitations under the License.

function compile_fuzzer {
fuzzer=$(basename $1)
fuzzer=$(basename $1)

# Instrument all Go files relevant to this fuzzer, compile and store in $fuzzer.a
go-fuzz -o $fuzzer.a github.com/dvyukov/go-fuzz-corpus/$fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -o $fuzzer.a github.com/dvyukov/go-fuzz-corpus/$fuzzer

# Instrumented, compiled Go ($fuzzer.a) + libFuzzer = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o fuzzer-$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o fuzzer-$fuzzer

# Copy the fuzzer binary
cp fuzzer-$fuzzer $OUT
# Copy the fuzzer binary
cp fuzzer-$fuzzer $OUT

# Pack the seed corpus
zip -r fuzzer-${fuzzer}_seed_corpus.zip \
$GOPATH/src/github.com/dvyukov/go-fuzz-corpus/$fuzzer/corpus
# Pack the seed corpus
zip -r fuzzer-${fuzzer}_seed_corpus.zip \
$GOPATH/src/github.com/dvyukov/go-fuzz-corpus/$fuzzer/corpus

# Copy the seed corpus
cp fuzzer-${fuzzer}_seed_corpus.zip $OUT
# Copy the seed corpus
cp fuzzer-${fuzzer}_seed_corpus.zip $OUT
}

export -f compile_fuzzer
Expand Down
10 changes: 5 additions & 5 deletions projects/gonids/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
#
################################################################################

# build target function
function compile_fuzzer {
path=$1
function=$2
fuzzer=$3

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func $function -o $fuzzer.a $path

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}

compile_fuzzer /root/go/src/github.com/google/gonids/ FuzzParseRule fuzz_parserule
compile_fuzzer /root/go/src/github.com/google/gonids/ FuzzParseRule \
fuzz_parserule

unzip emerging.rules.zip
cd rules
Expand Down
7 changes: 3 additions & 4 deletions projects/kubernetes/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ set -o pipefail
set -o errexit
set -x

# Based on the function from oss-fuzz/projects/golang/build.sh script.
function compile_fuzzer {
local pkg=$1
local function=$2
local fuzzer="${pkg}_${function}"

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func "${function}" -o "${fuzzer}.a" "k8s.io/kubernetes/test/fuzz/${pkg}"

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE "${fuzzer}.a" -lpthread -o "${OUT}/${fuzzer}"
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE "${fuzzer}.a" -o "${OUT}/${fuzzer}"
}

compile_fuzzer "yaml" "FuzzDurationStrict"
Expand Down
7 changes: 3 additions & 4 deletions projects/syzkaller/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
#
################################################################################

# Based on the function from oss-fuzz/projects/golang/build.sh script.
function compile_fuzzer {
path=$1
function=$2
fuzzer=$3

# Instrument all Go files relevant to this fuzzer
# Compile and instrument all Go files relevant to this fuzz target.
go-fuzz -func $function -o $fuzzer.a $path

# Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer
# Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
}

compile_fuzzer ./pkg/compiler Fuzz compiler_fuzzer
Expand Down

0 comments on commit b881b6a

Please sign in to comment.