Skip to content

Commit f9031ca

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

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-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

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

.clusterfuzzlite/project.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: python
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)