Line | Count | Source |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <string> |
16 | | #include "re2/re2.h" |
17 | | |
18 | 51.9k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
19 | 51.9k | if (size < 3 || size > 64) return 0; |
20 | 51.8k | uint16_t f = (data[0] << 16) + data[1]; |
21 | 51.8k | RE2::Options opt; |
22 | 51.8k | opt.set_log_errors(false); |
23 | 51.8k | if (f & 1) opt.set_encoding(RE2::Options::EncodingLatin1); |
24 | 51.8k | opt.set_posix_syntax(f & 2); |
25 | 51.8k | opt.set_longest_match(f & 4); |
26 | 51.8k | opt.set_literal(f & 8); |
27 | 51.8k | opt.set_never_nl(f & 16); |
28 | 51.8k | opt.set_dot_nl(f & 32); |
29 | 51.8k | opt.set_never_capture(f & 64); |
30 | 51.8k | opt.set_case_sensitive(f & 128); |
31 | 51.8k | opt.set_perl_classes(f & 256); |
32 | 51.8k | opt.set_word_boundary(f & 512); |
33 | 51.8k | opt.set_one_line(f & 1024); |
34 | 51.8k | const char *b = reinterpret_cast<const char*>(data) + 2; |
35 | 51.8k | const char *e = reinterpret_cast<const char*>(data) + size; |
36 | 51.8k | std::string s1(b, e); |
37 | 51.8k | RE2 re(s1, opt); |
38 | 51.8k | if (re.ok()) |
39 | 39.1k | RE2::FullMatch(s1, re); |
40 | 51.8k | return 0; |
41 | 51.9k | } |