summaryrefslogtreecommitdiff
path: root/libcxxabi/fuzz
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-12-28 03:28:29 +0000
committerKostya Serebryany <kcc@google.com>2016-12-28 03:28:29 +0000
commit4eb60cb9c9f4ee111f843f404752024ceb61819c (patch)
tree76dd7634e600b9ddbb5129d0ddfbc62473779e30 /libcxxabi/fuzz
parent9900d18bab2075ae99884e4faef1243980fa4bce (diff)
downloadllvm-4eb60cb9c9f4ee111f843f404752024ceb61819c.tar.gz
add cxa_demangle_fuzzer
Summary: All easy-to-find bugs in cxa_demangle where fixed now (https://bugs.chromium.org/p/chromium/issues/detail?id=606626) except for one (https://llvm.org/bugs/show_bug.cgi?id=31031). Now I'd like to properly integrate this fuzzer with the source tree and then run the fuzzer continuously on https://github.com/google/oss-fuzz Reviewers: compnerd, mclow.lists, mehdi_amini Subscribers: cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D28133 llvm-svn: 290650
Diffstat (limited to 'libcxxabi/fuzz')
-rw-r--r--libcxxabi/fuzz/CMakeLists.txt11
-rw-r--r--libcxxabi/fuzz/cxa_demangle_fuzzer.cpp15
2 files changed, 26 insertions, 0 deletions
diff --git a/libcxxabi/fuzz/CMakeLists.txt b/libcxxabi/fuzz/CMakeLists.txt
new file mode 100644
index 000000000000..017427e4631d
--- /dev/null
+++ b/libcxxabi/fuzz/CMakeLists.txt
@@ -0,0 +1,11 @@
+# See http://llvm.org/docs/LibFuzzer.html
+if( LLVM_USE_SANITIZE_COVERAGE )
+ add_executable(cxa_demangle_fuzzer
+ cxa_demangle_fuzzer.cpp
+ ../src/cxa_demangle.cpp
+ )
+
+ target_link_libraries(cxa_demangle_fuzzer
+ LLVMFuzzer
+ )
+endif()
diff --git a/libcxxabi/fuzz/cxa_demangle_fuzzer.cpp b/libcxxabi/fuzz/cxa_demangle_fuzzer.cpp
new file mode 100644
index 000000000000..cc9b193670d3
--- /dev/null
+++ b/libcxxabi/fuzz/cxa_demangle_fuzzer.cpp
@@ -0,0 +1,15 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+extern "C" char *
+__cxa_demangle(const char *mangled_name, char *buf, size_t *n, int *status);
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ char *str = new char[size+1];
+ memcpy(str, data, size);
+ str[size] = 0;
+ free(__cxa_demangle(str, 0, 0, 0));
+ delete [] str;
+ return 0;
+}