Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 215a3d1

Browse files
committed
update fuzzit.sh
1 parent b906178 commit 215a3d1

File tree

3 files changed

+80
-47
lines changed

3 files changed

+80
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Regression stage
155155
* create a local regression fuzzing job - This will pull all the generated corpuses and run them through
156156
the fuzzing binary. If new bugs are introduced this will fail the CI and alert
157157

158-
Here is the relevant snippet from the [./ci/fuzzit.sh](https://github.com/fuzzitdev/example-go/blob/master/ci/fuzzit.sh)
158+
Here is the relevant snippet from the [fuzzit.sh](https://github.com/fuzzitdev/example-go/blob/master/fuzzit.sh)
159159
which is being run by [.travis.yml](https://github.com/fuzzitdev/example-go/blob/master/.travis.yml)
160160

161161
```bash

ci/fuzzit.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

fuzzit.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
set -xe
3+
4+
# name of the organization in https://app.fuzzit.dev
5+
export FUZZIT_ORG="example-go"
6+
# github project repository
7+
export REPO="fuzzitdev/example-go"
8+
9+
# target name can only contain lower-case letters (a-z), digits (0-9) and a dash (-)
10+
TARGET=parse-complex
11+
12+
install_fuzzit () {
13+
# or latest version:
14+
# https://github.com/fuzzitdev/fuzzit/releases/latest/download/fuzzit_Linux_x86_64
15+
wget -q -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.17/fuzzit_Linux_x86_64
16+
chmod a+x fuzzit
17+
}
18+
19+
build_fuzzing_targets () {
20+
## go-fuzz doesn't support modules for now, so ensure we do everything
21+
## in the old style GOPATH way
22+
export GO111MODULE="off"
23+
24+
## Install go-fuzz
25+
go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
26+
27+
# download dependencies into ${GOPATH}
28+
# -d : only download (don't install)f
29+
# -v : verbose
30+
# -u : use the latest version
31+
# will be different if you use vendoring or a dependency manager
32+
# like godep
33+
go get -d -v -u ./...
34+
35+
go-fuzz-build -libfuzzer -o ${TARGET}.a .
36+
clang -fsanitize=fuzzer ${TARGET}.a -o ${TARGET}
37+
}
38+
39+
check_api_key_set () {
40+
if [ -z "${FUZZIT_API_KEY}" ]; then
41+
echo "Please set env variable FUZZIT_API_KEY to api key for your project"
42+
echo "Api key for your account: https://app.fuzzit.dev/orgs/${FUZZIT_ORG}/settings"
43+
exit 1
44+
fi
45+
}
46+
47+
build_and_upload_for_fuzzing () {
48+
check_api_key_set
49+
50+
build_fuzzing_targets
51+
install_fuzzit
52+
53+
# create fuzzing target on the server if it doesn't already exist
54+
./fuzzit create target ${TARGET} || true
55+
56+
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
57+
GIT_COMMIT=`git rev-parse --short HEAD`
58+
59+
# upload fuzz target for long fuzz testing on fuzzit.dev server
60+
./fuzzit create job --branch $GIT_BRANCH --revision $GIT_COMMIT ${TARGET} ${TARGET}
61+
}
62+
63+
build_and_run_regression_fuzzing () {
64+
build_fuzzing_targets
65+
install_fuzzit
66+
67+
# run short, regression fuzzing job locally
68+
./fuzzit create job --local ${FUZZIT_ORG}/${TARGET} ${TARGET}
69+
}
70+
71+
if [ "fuzzing" == $1 ]; then
72+
build_and_upload_for_fuzzing
73+
elif [ "regression" == $1 ]; then
74+
build_and_run_regression_fuzzing
75+
else
76+
echo "call me with job type: 'fuzzing' or 'regression'"
77+
echo "see https://github.com/fuzzitdev/example-go/blob/master/.travis.yml"
78+
exit 1
79+
fi

0 commit comments

Comments
 (0)