1 /* libfuzzer test code for oniguruma
2 * author: Hanno Böck, license: CC0/public domain
3
4 Usage:
5 * compile oniguruma with something like
6 ./configure CC=clang LD=clang CFLAGS="-fsanitize-coverage=edge -fsanitize=address" \
7 LDFLAGS="-fsanitize-coverage=edge -fsanitize=address"
8 * Compile libfuzzer stub and link against static libonig.a and libFuzzer.a:
9 clang++ libfuzzer-onig.cpp src/.libs/libonig.a libFuzzer.a -o libfuzzer-onig \
10 -fsanitize-coverage=edge -fsanitize=address
11 * Put sample patterns in directory "in/"
12 * Run
13 ./libfuzzer-onig in
14
15 Consult libfuzzer docs for further details and how to create libFuzzer.a:
16 http://llvm.org/docs/LibFuzzer.html
17
18 */
19 #include <stdint.h>
20 #include <string.h>
21 #include <oniguruma.h>
22
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size)
24 {
25 regex_t *reg;
26 OnigEncoding enc;
27
28 enc = ONIG_ENCODING_UTF8;
29
30 #ifdef FULL_TEST
31 onig_initialize(&enc, 1);
32 onig_set_retry_limit_in_match(120);
33 onig_set_parse_depth_limit(120);
34 #endif
35
36 if (onig_new(®, Data, Data + Size, ONIG_OPTION_DEFAULT, enc,
37 ONIG_SYNTAX_DEFAULT, 0) == 0)
38 onig_free(reg);
39
40 #ifdef FULL_TEST
41 onig_end();
42 #endif
43
44 return 0;
45 }
46