Coverage Report

Created: 2024-08-17 11:02

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