diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 5eb01090a4fd..dbb3602315f3 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -432,4 +432,5 @@ if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED) "available!") else() add_subdirectory(test) + add_subdirectory(fuzz) endif() 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 +#include +#include +#include +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; +}