forked from google/fuzzer-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.cc
29 lines (28 loc) · 939 Bytes
/
target.cc
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
// Copyright 2016 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
#include <string>
#include "re2/re2.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 3) return 0;
uint16_t f = (data[0] << 16) + data[1];
RE2::Options opt;
opt.set_log_errors(false);
if (f & 1) opt.set_encoding(RE2::Options::EncodingLatin1);
opt.set_posix_syntax(f & 2);
opt.set_longest_match(f & 4);
opt.set_literal(f & 8);
opt.set_never_nl(f & 16);
opt.set_dot_nl(f & 32);
opt.set_never_capture(f & 64);
opt.set_case_sensitive(f & 128);
opt.set_perl_classes(f & 256);
opt.set_word_boundary(f & 512);
opt.set_one_line(f & 1024);
const char *b = reinterpret_cast<const char*>(data) + 2;
const char *e = reinterpret_cast<const char*>(data) + size;
std::string s1(b, e);
RE2 re(s1, opt);
if (re.ok())
RE2::FullMatch(s1, re);
return 0;
}