MCPcopy Create free account
hub / github.com/boostorg/json / FuzzHelper

Class FuzzHelper

fuzzing/fuzz_parser.cpp:20–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace boost::json;
19
20struct FuzzHelper {
21 parse_options opt;
22 string_view jsontext;
23 std::size_t memlimit1;
24 std::size_t memlimit2;
25 bool res;
26 void run(stream_parser& p) {
27 boost::system::error_code ec;
28
29 // Write the first part of the buffer
30 p.write( jsontext, ec);
31
32 if(! ec)
33 p.finish( ec );
34
35 // Take ownership of the resulting value.
36 if(! ec)
37 {
38 value jv = p.release();
39 res=serialize(jv).size()==42;
40 } else
41 res=false;
42 }
43
44 // easy case - everything default
45 void useDefault() {
46 stream_parser p(storage_ptr{}, opt);
47 run(p);
48 }
49
50 void useMonotonic() {
51 monotonic_resource mr;
52 stream_parser p(storage_ptr{}, opt);
53 p.reset( &mr );
54
55 run(p);
56 }
57
58 void useLocalBuffer() {
59 std::unique_ptr<unsigned char[]> temp(new unsigned char[memlimit1]);
60 stream_parser p(
61 storage_ptr(),
62 opt,
63 temp.get(),
64 memlimit1);
65 run(p);
66 }
67
68 void useDynLess() {
69 // this is on the heap because the size is chosen dynamically
70 std::unique_ptr<unsigned char[]> temp(new unsigned char[memlimit1]);
71 stream_parser p(get_null_resource(),
72 opt,
73 temp.get(),
74 memlimit1);
75
76 // this is on the heap because the size is chosen dynamically
77 std::unique_ptr<unsigned char[]> buf(new unsigned char[memlimit2]);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected