-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathparser_parse.cpp
67 lines (52 loc) · 1.6 KB
/
parser_parse.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
#include <cassert>
#include <cstdint>
#include <cstdio>
#include "parser.h"
#ifdef NDEBUG
#error "This fuzz target won't work correctly with NDEBUG defined, which will cause asserts to be eliminated"
#endif
using std::size_t;
static char PARSER_KEY[16384];
static char PARSER_VALUE[16384];
parser_tx_t txObj;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
parser_context_t ctx;
parser_error_t rc;
rc = parser_parse(&ctx, data, size);
if (rc != parser_ok) {
return 0;
}
rc = parser_validate(&ctx);
if (rc != parser_ok) {
return 0;
}
uint8_t num_items;
rc = parser_getNumItems(&ctx, &num_items);
if (rc != parser_ok) {
fprintf(stderr,
"error in parser_getNumItems: %s\n",
parser_getErrorDescription(rc));
assert(false);
}
for (uint8_t i = 0; i < num_items; i += 1) {
uint8_t page_idx = 0;
uint8_t page_count = 1;
while (page_idx < page_count) {
rc = parser_getItem(&ctx, i,
PARSER_KEY, sizeof(PARSER_KEY),
PARSER_VALUE, sizeof(PARSER_VALUE),
page_idx, &page_count);
if (rc != parser_ok) {
fprintf(stderr,
"error getting item %u at page index %u: %s\n",
(unsigned)i,
(unsigned)page_idx,
parser_getErrorDescription(rc));
assert(false);
}
page_idx += 1;
}
}
return 0;
}