]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] add fuzzer test for libxml2, finds https://bugzilla.gnome.org/show_bug...
authorKostya Serebryany <kcc@google.com>
Sat, 1 Oct 2016 07:37:40 +0000 (07:37 +0000)
committerKostya Serebryany <kcc@google.com>
Sat, 1 Oct 2016 07:37:40 +0000 (07:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283024 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/build.sh [new file with mode: 0755]
lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/target.cc [new file with mode: 0644]
lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/test.sh [new file with mode: 0755]

diff --git a/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/build.sh b/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/build.sh
new file mode 100755 (executable)
index 0000000..5693579
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+. $(dirname $0)/../common.sh
+
+build_lib() {
+  rm -rf BUILD
+  cp -rf SRC BUILD
+  (cd BUILD && ./autogen.sh && CXX="clang++ $FUZZ_CXXFLAGS" CC="clang $FUZZ_CXXFLAGS" CCLD="clang++ $FUZZ_CXXFLAGS"  ./configure && make -j $JOBS)
+}
+
+get_git_tag git://git.gnome.org/libxml2  v2.9.2 SRC
+build_lib
+build_libfuzzer
+clang++ -std=c++11  $SCRIPT_DIR/target.cc  $FUZZ_CXXFLAGS  -I BUILD/include BUILD/.libs/libxml2.a libFuzzer.a  -lz -o $EXECUTABLE_NAME_BASE
diff --git a/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/target.cc b/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/target.cc
new file mode 100644 (file)
index 0000000..3fdcb6f
--- /dev/null
@@ -0,0 +1,16 @@
+#include <string>
+#include <vector>
+#include "libxml/xmlversion.h"
+#include "libxml/parser.h"
+#include "libxml/HTMLparser.h"
+#include "libxml/tree.h"
+
+void ignore (void * ctx, const char * msg, ...) {}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  xmlSetGenericErrorFunc(NULL, &ignore);
+  if (auto doc = xmlReadMemory(reinterpret_cast<const char *>(data), size,
+                               "noname.xml", NULL, 0))
+    xmlFreeDoc(doc);
+  return 0;
+}
diff --git a/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/test.sh b/lib/Fuzzer/fuzzer-test-suite/libxml2-v2.9.2/test.sh
new file mode 100755 (executable)
index 0000000..d645e1d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+set -x
+. $(dirname $0)/../common.sh
+
+get_git_revision https://github.com/mcarpenter/afl be3e88d639da5350603f6c0fee06970128504342 afl
+rm -rf $CORPUS
+mkdir $CORPUS
+[ -e $EXECUTABLE_NAME_BASE ] && ./$EXECUTABLE_NAME_BASE -artifact_prefix=$CORPUS/ -jobs=$JOBS -dict=afl/dictionaries/xml.dict -workers=$JOBS $CORPUS
+grep "AddressSanitizer: heap-buffer-overflow" fuzz-0.log