Skip to content

Commit 4b730be

Browse files
committed
Add initial fuzzing test
1 parent 815dd0c commit 4b730be

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.clusterfuzzlite/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM gcr.io/oss-fuzz-base/base-builder-python:v1
2+
COPY . $SRC/globaleaks-whistleblowing-software
3+
WORKDIR globaleaks-whistleblowing-software
4+
COPY .clusterfuzzlite/build.sh $SRC/

.clusterfuzzlite/build.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash -eu
2+
3+
pip3 install -r backend/requirements.txt
4+
pip3 install ./backend
5+
6+
# Build fuzzers into $OUT. These could be detected in other ways.
7+
for fuzzer in $(find $SRC -name 'fuzzer_*.py'); do
8+
fuzzer_basename=$(basename -s .py $fuzzer)
9+
fuzzer_package=${fuzzer_basename}.pkg
10+
11+
# To avoid issues with Python version conflicts, or changes in environment
12+
# over time, we use pyinstaller to create a standalone
13+
# package. Though not necessarily required for reproducing issues, this is
14+
# required to keep fuzzers working properly.
15+
pyinstaller --distpath $OUT --onefile --name $fuzzer_package $fuzzer
16+
17+
# Create execution wrapper. Atheris requires that certain libraries are
18+
# preloaded, so this is also done here to ensure compatibility and simplify
19+
# test case reproduction. Since this helper script is what will
20+
# actually execute, it is also always required.
21+
# NOTE: If you are fuzzing python-only code and do not have native C/C++
22+
# extensions, then remove the LD_PRELOAD line below as preloading sanitizer
23+
# library is not required and can lead to unexpected startup crashes.
24+
echo "#!/bin/sh
25+
# LLVMFuzzerTestOneInput for fuzzer detection.
26+
this_dir=\$(dirname \"\$0\")
27+
LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \
28+
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
29+
\$this_dir/$fuzzer_package \$@" > $OUT/$fuzzer_basename
30+
chmod +x $OUT/$fuzzer_basename
31+
done

.clusterfuzzlite/project.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: python

.github/workflows/cflite.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: ClusterFuzzLite fuzzing
2+
3+
on: [ push, pull_request ]
4+
5+
# Declare default permissions as read only.
6+
permissions: read-all
7+
8+
jobs:
9+
ClusterFuzzLite:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
sanitizer: [address]
15+
steps:
16+
- name: Build Fuzzers (${{ matrix.sanitizer }})
17+
id: build
18+
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
19+
with:
20+
sanitizer: ${{ matrix.sanitizer }}
21+
language: c
22+
bad-build-check: false
23+
- name: Run Fuzzers (${{ matrix.sanitizer }})
24+
id: run
25+
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
26+
with:
27+
fuzz-seconds: 100
28+
mode: 'code-change'
29+
report-unreproducible-crashes: false
30+
sanitizer: ${{ matrix.sanitizer }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import atheris
2+
import sys
3+
from globaleaks.rest import api
4+
5+
def fuzz_target(input_data: bytes):
6+
# Convert the fuzzed byte input to a string
7+
fuzz_input = input_data.decode(errors="ignore")
8+
9+
# Call the fuzz test handler function with the decoded string
10+
fuzz_test_resolve_handler(fuzz_input)
11+
12+
def main():
13+
# Set up Atheris and pass the fuzz target function
14+
atheris.Setup(sys.argv, fuzz_target)
15+
16+
# Start fuzzing
17+
atheris.Fuzz()
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)