aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2021-02-26 10:22:32 -0800
committerGravatar GitHub <noreply@github.com>2021-02-26 18:22:32 +0000
commitaab2e82b4acfb37ba5cbc9ffb89481d316fe5193 (patch)
treeb2d07ab61c24777f685f73f606d7266571a21fa1
parent98a2db88c4f4d95728bc8af7494ccf5cd798edc2 (diff)
[jazzer][java-example] Fix native library loading. (#5262)
Prior to this change, native library loading failed for two reasons: 1. Loading from current working directory instead of the fuzzer's directory. 2. Using ASAN_OPTIONS=handle_segv=2. Fix these issues by doing the following. 1. Adding the fuzzer's directory to LD_LIBRARY_PATH instead of "." 2. Specifying handle_segv=1 in ASAN_OPTIONS. Related: https://github.com/google/oss-fuzz/issues/5178
-rw-r--r--projects/java-example/Dockerfile2
-rwxr-xr-xprojects/java-example/build.sh5
-rw-r--r--projects/java-example/default.options2
-rwxr-xr-xprojects/json-sanitizer/build.sh2
4 files changed, 7 insertions, 4 deletions
diff --git a/projects/java-example/Dockerfile b/projects/java-example/Dockerfile
index 92f278f7..316e9a88 100644
--- a/projects/java-example/Dockerfile
+++ b/projects/java-example/Dockerfile
@@ -19,6 +19,6 @@ FROM gcr.io/oss-fuzz-base/base-builder
COPY build.sh $SRC/
COPY ExampleFuzzerNative.h ExampleFuzzerNative.cpp $SRC/
-COPY ExampleFuzzer.java ExampleValueProfileFuzzer.java ExampleFuzzerNative.java $SRC/
+COPY ExampleFuzzer.java ExampleValueProfileFuzzer.java ExampleFuzzerNative.java default.options $SRC/
WORKDIR $SRC/
diff --git a/projects/java-example/build.sh b/projects/java-example/build.sh
index d9c4ee2b..63f4c95f 100755
--- a/projects/java-example/build.sh
+++ b/projects/java-example/build.sh
@@ -36,11 +36,12 @@ for fuzzer in $(find $SRC -name '*Fuzzer.java' -or -name '*FuzzerNative.java');
driver=jazzer_driver
fi
+ cp default.options $OUT/"$fuzzer_basename".options
# Create execution wrapper.
echo "#!/bin/sh
# LLVMFuzzerTestOneInput for fuzzer detection.
this_dir=\$(dirname \"\$0\")
-LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":. \
+LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
\$this_dir/$driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
--cp=$RUNTIME_CLASSPATH \
@@ -48,4 +49,4 @@ ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm
--jvm_args=\"-Xmx2048m\" \
\$@" > $OUT/$fuzzer_basename
chmod u+x $OUT/$fuzzer_basename
-done \ No newline at end of file
+done
diff --git a/projects/java-example/default.options b/projects/java-example/default.options
new file mode 100644
index 00000000..2ab00131
--- /dev/null
+++ b/projects/java-example/default.options
@@ -0,0 +1,2 @@
+[asan]
+handle_segv=1 \ No newline at end of file
diff --git a/projects/json-sanitizer/build.sh b/projects/json-sanitizer/build.sh
index faa6ee78..4010f884 100755
--- a/projects/json-sanitizer/build.sh
+++ b/projects/json-sanitizer/build.sh
@@ -47,7 +47,7 @@ for fuzzer in $(find $SRC -name '*Fuzzer.java'); do
echo "#!/bin/sh
# LLVMFuzzerTestOneInput for fuzzer detection.
this_dir=\$(dirname \"\$0\")
-LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\" \
+LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \
\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
--cp=$RUNTIME_CLASSPATH \
--target_class=$fuzzer_basename \