aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2021-03-18 21:34:12 +0100
committerAndrea Fioraldi <andreafioraldi@gmail.com>2021-03-18 21:34:12 +0100
commit166c8f93b5166087255265f9a00fd8babbd432d7 (patch)
tree62ff5c970bac9c73982f75a96b0c52665ab3c349
parent9393452d1c390d9c8ba3fd045107e6bb7dc312b4 (diff)
downloadAFLplusplus-166c8f93b5166087255265f9a00fd8babbd432d7.tar.gz
test-dlopen llvm test
-rw-r--r--test-instr.c4
-rw-r--r--test/test-dlopen.c19
-rwxr-xr-xtest/test-llvm.sh38
3 files changed, 61 insertions, 0 deletions
diff --git a/test-instr.c b/test-instr.c
index 00799103..4129a5b4 100644
--- a/test-instr.c
+++ b/test-instr.c
@@ -18,6 +18,10 @@
#include <sys/stat.h>
#include <fcntl.h>
+#ifdef TEST_SHARED_OBJECT
+#define main main_exported
+#endif
+
int main(int argc, char **argv) {
int fd = 0;
diff --git a/test/test-dlopen.c b/test/test-dlopen.c
new file mode 100644
index 00000000..e4524536
--- /dev/null
+++ b/test/test-dlopen.c
@@ -0,0 +1,19 @@
+#include <dlfcn.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv) {
+
+ if (!getenv("TEST_DLOPEN_TARGET"))
+ return 1;
+ void* lib = dlopen(getenv("TEST_DLOPEN_TARGET"), RTLD_LAZY);
+ if (!lib) {
+ perror(dlerror());
+ return 2;
+ }
+ int (*func)(int, char**) = dlsym(lib, "main_exported");
+ if (!func)
+ return 3;
+
+ return func(argc, argv);
+
+}
diff --git a/test/test-llvm.sh b/test/test-llvm.sh
index aa36af1b..fb1c90ac 100755
--- a/test/test-llvm.sh
+++ b/test/test-llvm.sh
@@ -43,6 +43,44 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
$ECHO "$RED[!] llvm_mode failed"
CODE=1
}
+ ../afl-clang-fast -DTEST_SHARED_OBJECT=1 -z defs -fPIC -shared -o test-instr.so ../test-instr.c > /dev/null 2>&1
+ test -e test-instr.so && {
+ $ECHO "$GREEN[+] llvm_mode shared object with -z defs compilation succeeded"
+ ../afl-clang-fast -o test-dlopen.plain test-dlopen.c -ldl > /dev/null 2>&1
+ test -e test-dlopen.plain && {
+ $ECHO "$GREEN[+] llvm_mode test-dlopen compilation succeeded"
+
+ echo 0 | TEST_DLOPEN_TARGET=./test-instr.so AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o test-dlopen.plain.0 -r -- ./test-dlopen.plain > /dev/null 2>&1
+ TEST_DLOPEN_TARGET=./test-instr.so AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o test-dlopen.plain.1 -r -- ./test-dlopen.plain < /dev/null > /dev/null 2>&1
+ test -e test-dlopen.plain.0 -a -e test-dlopen.plain.1 && {
+ diff test-dlopen.plain.0 test-dlopen.plain.1 > /dev/null 2>&1 && {
+ $ECHO "$RED[!] llvm_mode test-dlopen instrumentation should be different on different input but is not"
+ CODE=1
+ } || {
+ $ECHO "$GREEN[+] llvm_mode test-dlopen instrumentation present and working correctly"
+ TUPLES=`echo 0|TEST_DLOPEN_TARGET=./test-instr.so AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- ./test-dlopen.plain 2>&1 | grep Captur | awk '{print$3}'`
+ test "$TUPLES" -gt 2 -a "$TUPLES" -lt 8 && {
+ $ECHO "$GREEN[+] llvm_mode test-dlopen run reported $TUPLES instrumented locations which is fine"
+ } || {
+ $ECHO "$RED[!] llvm_mode test-dlopen instrumentation produces weird numbers: $TUPLES"
+ CODE=1
+ }
+ test "$TUPLES" -lt 3 && SKIP=1
+ true
+ }
+ } || {
+ $ECHO "$RED[!] llvm_mode test-dlopen instrumentation failed"
+ CODE=1
+ }
+ } || {
+ $ECHO "$RED[!] llvm_mode test-dlopen compilation failed"
+ CODE=1
+ }
+ rm -f test-dlopen.plain test-dlopen.plain.0 test-dlopen.plain.1 test-instr.so
+ } || {
+ $ECHO "$RED[!] llvm_mode shared object with -z defs compilation failed"
+ CODE=1
+ }
test -e test-compcov.harden && test_compcov_binary_functionality ./test-compcov.harden && {
grep -Eq$GREPAOPTION 'stack_chk_fail|fstack-protector-all|fortified' test-compcov.harden > /dev/null 2>&1 && {
$ECHO "$GREEN[+] llvm_mode hardened mode succeeded and is working"