/src/llvm-project/libcxx/test/libcxx/fuzzing/regex.pass.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===----------------------------------------------------------------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | // UNSUPPORTED: c++03, c++11 |
10 | | // UNSUPPORTED: no-exceptions |
11 | | // UNSUPPORTED: no-localization |
12 | | |
13 | | #include <cstddef> |
14 | | #include <cstdint> |
15 | | #include <regex> |
16 | | #include <string> |
17 | | |
18 | | #include "fuzz.h" |
19 | | |
20 | | template <std::regex_constants::syntax_option_type Syntax> |
21 | 0 | static int regex_test(const std::uint8_t *data, std::size_t size) { |
22 | 0 | if (size == 0) |
23 | 0 | return 0; |
24 | | |
25 | 0 | std::string s((const char *)data, size); |
26 | 0 | std::regex re; |
27 | 0 | try { |
28 | 0 | re.assign(s, Syntax); |
29 | 0 | } catch (std::regex_error &) { |
30 | | // the data represents an invalid regex, ignore this test case |
31 | 0 | return 0; |
32 | 0 | } |
33 | | |
34 | 0 | auto match = std::regex_match(s, re); |
35 | 0 | (void)match; |
36 | 0 | return 0; // always pretend we succeeded -- we're only looking for crashes |
37 | 0 | } Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)64>(unsigned char const*, unsigned long) Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)16>(unsigned char const*, unsigned long) Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)0>(unsigned char const*, unsigned long) Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)256>(unsigned char const*, unsigned long) Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)32>(unsigned char const*, unsigned long) Unexecuted instantiation: regex.pass.cpp:int regex_test<(std::__1::regex_constants::syntax_option_type)128>(unsigned char const*, unsigned long) |
38 | | |
39 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) { |
40 | | return regex_test<std::regex_constants::awk>(data, size) || |
41 | | regex_test<std::regex_constants::basic>(data, size) || |
42 | | regex_test<std::regex_constants::ECMAScript>(data, size) || |
43 | | regex_test<std::regex_constants::egrep>(data, size) || |
44 | | regex_test<std::regex_constants::extended>(data, size) || |
45 | | regex_test<std::regex_constants::grep>(data, size); |
46 | | } |