forked from sdarwin/json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_parser.cpp
More file actions
56 lines (47 loc) · 1.09 KB
/
fuzz_parser.cpp
File metadata and controls
56 lines (47 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2019 Vinnie Falco ([email protected])
// Copyright (c) 2020 Paul Dreik ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/json
//
#include <boost/json/parser.hpp>
using namespace boost::json;
bool
fuzz_parser(string_view sv)
{
parser p;
error_code ec;
// This must be called once before parsing every new JSON
p.reset();
// Write the first part of the buffer
p.write( sv.data(), sv.size(), ec);
if(! ec)
p.finish( ec );
// Take ownership of the resulting value.
if(! ec)
{
value jv = p.release( ec );
if(! ec )
return jv.is_number();
}
return false;
}
extern "C"
int
LLVMFuzzerTestOneInput(
const uint8_t* data, size_t size)
{
try
{
string_view view{
reinterpret_cast<const char*>(
data), size};
fuzz_parser(view);
}
catch(...)
{
}
return 0;
}