/src/openvswitch/tests/oss-fuzz/json_parser_target.c
Line | Count | Source |
1 | | #include <config.h> |
2 | | #include "fuzzer.h" |
3 | | #include "jsonrpc.h" |
4 | | #include "openvswitch/json.h" |
5 | | #include "ovsdb-error.h" |
6 | | #include "ovsdb/table.h" |
7 | | #include <assert.h> |
8 | | #include <string.h> |
9 | | |
10 | | int |
11 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
12 | 4.05k | { |
13 | 4.05k | if (!size || data[size - 1]) { |
14 | 16 | return 0; |
15 | 16 | } |
16 | | |
17 | 4.03k | struct json *j1 = json_from_string((const char *)data); |
18 | 4.03k | if (j1->type == JSON_STRING) { |
19 | 2.56k | json_destroy(j1); |
20 | 2.56k | return 0; |
21 | 2.56k | } |
22 | | |
23 | 1.46k | free(json_to_string(j1, JSSF_SORT | JSSF_PRETTY)); |
24 | | |
25 | 1.46k | struct jsonrpc_msg *msg; |
26 | 1.46k | char *error = jsonrpc_msg_from_json(j1, &msg); /* Frees 'j1'. */ |
27 | 1.46k | if (error) { |
28 | 1.21k | free(error); |
29 | 1.21k | return 0; |
30 | 1.21k | } |
31 | | |
32 | 258 | struct json *j2 = jsonrpc_msg_to_json(msg); /* Frees 'msg'. */ |
33 | 258 | if (j2->type == JSON_STRING) { |
34 | 0 | json_destroy(j2); |
35 | 0 | return 0; |
36 | 0 | } |
37 | | |
38 | 258 | free(json_to_string(j2, JSSF_SORT | JSSF_PRETTY)); |
39 | 258 | json_destroy(j2); |
40 | | |
41 | 258 | return 0; |
42 | 258 | } |