diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2019-11-29 11:26:57 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2019-11-29 11:26:57 +0100 |
commit | 7f4e90f2759d6a15812172ee19f3ad5b58940beb (patch) | |
tree | 5f90c63b8ba73f4ecd23d6e642c1ab34dccea033 /harnesses/libfuzzer-onig.cpp | |
parent | 68d1ec60c90d27c511d51ce0bef44b132a7ddf11 (diff) | |
parent | 7e149a97d276ce3b4c5e34f965766c8e40e03fef (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'harnesses/libfuzzer-onig.cpp')
-rw-r--r-- | harnesses/libfuzzer-onig.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/harnesses/libfuzzer-onig.cpp b/harnesses/libfuzzer-onig.cpp new file mode 100644 index 0000000..526c826 --- /dev/null +++ b/harnesses/libfuzzer-onig.cpp @@ -0,0 +1,45 @@ +/* libfuzzer test code for oniguruma + * author: Hanno Böck, license: CC0/public domain + +Usage: +* compile oniguruma with something like + ./configure CC=clang LD=clang CFLAGS="-fsanitize-coverage=edge -fsanitize=address" \ + LDFLAGS="-fsanitize-coverage=edge -fsanitize=address" +* Compile libfuzzer stub and link against static libonig.a and libFuzzer.a: + clang++ libfuzzer-onig.cpp src/.libs/libonig.a libFuzzer.a -o libfuzzer-onig \ + -fsanitize-coverage=edge -fsanitize=address +* Put sample patterns in directory "in/" +* Run + ./libfuzzer-onig in + +Consult libfuzzer docs for further details and how to create libFuzzer.a: +http://llvm.org/docs/LibFuzzer.html + + */ +#include <stdint.h> +#include <string.h> +#include <oniguruma.h> + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size) +{ + regex_t *reg; + OnigEncoding enc; + + enc = ONIG_ENCODING_UTF8; + +#ifdef FULL_TEST + onig_initialize(&enc, 1); + onig_set_retry_limit_in_match(120); + onig_set_parse_depth_limit(120); +#endif + + if (onig_new(®, Data, Data + Size, ONIG_OPTION_DEFAULT, enc, + ONIG_SYNTAX_DEFAULT, 0) == 0) + onig_free(reg); + +#ifdef FULL_TEST + onig_end(); +#endif + + return 0; +} |