/src/boost/libs/json/fuzzing/fuzz_parse.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) |
3 | | // Copyright (c) 2020 Paul Dreik (github@pauldreik.se) |
4 | | // |
5 | | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
6 | | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
7 | | // |
8 | | // Official repository: https://github.com/boostorg/json |
9 | | // |
10 | | |
11 | | #include <boost/json/parse.hpp> |
12 | | |
13 | | using namespace boost::json; |
14 | | |
15 | | bool |
16 | | fuzz_parse(string_view sv) |
17 | 6.97k | { |
18 | 6.97k | boost::system::error_code ec; |
19 | 6.97k | value jv = parse( sv, ec ); |
20 | 6.97k | if(ec) |
21 | 4.61k | return false; |
22 | 2.36k | return jv.is_number(); |
23 | 6.97k | } |
24 | | |
25 | | extern "C" |
26 | | int |
27 | | LLVMFuzzerTestOneInput( |
28 | | const uint8_t* data, size_t size) |
29 | 23.0k | { |
30 | 23.0k | try |
31 | 23.0k | { |
32 | 23.0k | string_view s{reinterpret_cast< |
33 | 23.0k | const char*>(data), size}; |
34 | 23.0k | fuzz_parse(s); |
35 | 23.0k | } |
36 | 23.0k | catch(...) |
37 | 23.0k | { |
38 | 0 | } |
39 | 23.0k | return 0; |
40 | 23.0k | } |