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  | 80.8k  | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 
19  | 80.8k  |   if (size < 3 || size > 64) return 0;  | 
20  | 74.5k  |   uint16_t f = (data[0] << 16) + data[1];  | 
21  | 74.5k  |   RE2::Options opt;  | 
22  | 74.5k  |   opt.set_log_errors(false);  | 
23  | 74.5k  |   if (f & 1) opt.set_encoding(RE2::Options::EncodingLatin1);  | 
24  | 74.5k  |   opt.set_posix_syntax(f & 2);  | 
25  | 74.5k  |   opt.set_longest_match(f & 4);  | 
26  | 74.5k  |   opt.set_literal(f & 8);  | 
27  | 74.5k  |   opt.set_never_nl(f & 16);  | 
28  | 74.5k  |   opt.set_dot_nl(f & 32);  | 
29  | 74.5k  |   opt.set_never_capture(f & 64);  | 
30  | 74.5k  |   opt.set_case_sensitive(f & 128);  | 
31  | 74.5k  |   opt.set_perl_classes(f & 256);  | 
32  | 74.5k  |   opt.set_word_boundary(f & 512);  | 
33  | 74.5k  |   opt.set_one_line(f & 1024);  | 
34  | 74.5k  |   const char *b = reinterpret_cast<const char*>(data) + 2;  | 
35  | 74.5k  |   const char *e = reinterpret_cast<const char*>(data) + size;  | 
36  | 74.5k  |   std::string s1(b, e);  | 
37  | 74.5k  |   RE2 re(s1, opt);  | 
38  | 74.5k  |   if (re.ok())  | 
39  | 56.2k  |     RE2::FullMatch(s1, re);  | 
40  | 74.5k  |   return 0;  | 
41  | 80.8k  | }  |