summaryrefslogtreecommitdiff
path: root/contributed/libfuzzer-onig.cpp
blob: e137b73064a37ba92e9df972d0e4df552f43ab26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* 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);
#endif

  if (onig_new(&reg, Data, Data + Size, ONIG_OPTION_DEFAULT, enc,
               ONIG_SYNTAX_DEFAULT, 0) == 0)
    onig_free(reg);

#ifdef FULL_TEST
  onig_end();
#endif

  return 0;
}