|
1 | 1 | #!/bin/bash |
2 | 2 | set -xe |
3 | 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 |
| 4 | +## Build fuzzing targets |
| 5 | +## go-fuzz doesn't support modules for now, so ensure we do everything |
| 6 | +## in the old style GOPATH way |
| 7 | +export GO111MODULE="off" |
| 8 | + |
| 9 | +## Install go-fuzz |
| 10 | +go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build |
| 11 | + |
| 12 | +# download dependencies into ${GOPATH} |
| 13 | +# -d : only download (don't install)f |
| 14 | +# -v : verbose |
| 15 | +# -u : use the latest version |
| 16 | +# will be different if you use vendoring or a dependency manager |
| 17 | +# like godep |
| 18 | +go get -d -v -u ./... |
| 19 | + |
| 20 | +go-fuzz-build -libfuzzer -o ${TARGET}.a . |
| 21 | +clang -fsanitize=fuzzer ${TARGET}.a -o ${TARGET} |
| 22 | + |
| 23 | +## Install fuzzit specific version for production or latest version for development : |
| 24 | +# https://github.com/fuzzitdev/fuzzit/releases/latest/download/fuzzit_Linux_x86_64 |
| 25 | +wget -q -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.22/fuzzit_Linux_x86_64 |
| 26 | +chmod a+x fuzzit |
| 27 | + |
| 28 | +## upload fuzz target for long fuzz testing on fuzzit.dev server or run locally for regression |
| 29 | +./fuzzit create job --type ${1} fuzzitdev/parse-complex parse-complex |
0 commit comments