about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2020-08-03 11:30:34 +0200
committerAndrea Fioraldi <andreafioraldi@gmail.com>2020-08-03 11:30:34 +0200
commit9d82c3cf5e131030073d6a4df1b2102573a8ace4 (patch)
tree5825eb246eac3afc253b8f9089b2995a7ae9a35d
parent491cee669f858bfea2b0db2fe540200b0f2625e6 (diff)
downloadafl++-9d82c3cf5e131030073d6a4df1b2102573a8ace4.tar.gz
test for llvm cmplog
-rw-r--r--test/test-cmplog.c27
-rwxr-xr-xtest/test.sh22
2 files changed, 49 insertions, 0 deletions
diff --git a/test/test-cmplog.c b/test/test-cmplog.c
new file mode 100644
index 00000000..75efd887
--- /dev/null
+++ b/test/test-cmplog.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+int main(int argc, char *argv[]) {
+  char buf[1024];
+  ssize_t i;
+  if ((i = read(0, buf, sizeof(buf) - 1)) < 24)
+    return 0;
+  buf[i] = 0;
+  if (buf[0] != 'A')
+    return 0;
+  if (buf[1] != 'B')
+    return 0;
+  if (buf[2] != 'C')
+    return 0;
+  if (buf[3] != 'D')
+    return 0;
+  if (memcmp(buf + 4, "1234", 4) || memcmp(buf + 8, "EFGH", 4))
+    return 0;
+  if (strncmp(buf + 12, "IJKL", 4) == 0 && strcmp(buf + 16, "DEADBEEF") == 0)
+    abort();
+  return 0;
+}
+
diff --git a/test/test.sh b/test/test.sh
index dea9134f..46843d4a 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -423,6 +423,28 @@ test -e ../afl-clang-fast -a -e ../split-switches-pass.so && {
     CODE=1
   }
   rm -f test-compcov test.out instrumentlist.txt
+  AFL_LLVM_CMPLOG=1 ../afl-clang-fast -o test-cmplog test-cmplog.c > /dev/null 2>&1
+  test -e test-cmplog && {
+    $ECHO "$GREY[*] running afl-fuzz for llvm_mode cmplog, this will take approx 10 seconds"
+    {
+      mkdir -p in
+      echo 0000000000000000000000000 > in/in
+      ../afl-fuzz -m none -V10 -i in -o out -c./test-cmplog -- ./test-cmplog >>errors 2>&1
+    } >>errors 2>&1
+    test -n "$( ls out/crashes/id:000000* 2>/dev/null )" && {
+      $ECHO "$GREEN[+] afl-fuzz is working correctly with llvm_mode cmplog"
+    } || {
+      echo CUT------------------------------------------------------------------CUT
+      cat errors
+      echo CUT------------------------------------------------------------------CUT
+      $ECHO "$RED[!] afl-fuzz is not working correctly with llvm_mode cmplog"
+      CODE=1
+    }
+  } || {
+    $ECHO "$YELLOW[-] we cannot test llvm_mode cmplog because it is not present"
+    INCOMPLETE=1
+  }
+  rm -rf errors test-cmplog in
   ../afl-clang-fast -o test-persistent ../examples/persistent_demo/persistent_demo.c > /dev/null 2>&1
   test -e test-persistent && {
     echo foo | ../afl-showmap -m ${MEM_LIMIT} -o /dev/null -q -r ./test-persistent && {