]> git.proxmox.com Git - mirror_ovs.git/blob - tests/oss-fuzz/json_parser_target.c
oss-fuzz: Move oss-fuzz test harnesses and fuzzer configs to ovs source repo
[mirror_ovs.git] / tests / oss-fuzz / json_parser_target.c
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 {
13 if (!size || data[size - 1]) {
14 return 0;
15 }
16
17 struct json *j1 = json_from_string((const char *)data);
18 if (j1->type == JSON_STRING) {
19 json_destroy(j1);
20 return 0;
21 }
22
23 free(json_to_string(j1, JSSF_SORT | JSSF_PRETTY));
24
25 struct jsonrpc_msg *msg;
26 char *error = jsonrpc_msg_from_json(j1, &msg); /* Frees 'j1'. */
27 if (error) {
28 free(error);
29 return 0;
30 }
31
32 struct json *j2 = jsonrpc_msg_to_json(msg); /* Frees 'msg'. */
33 if (j2->type == JSON_STRING) {
34 json_destroy(j2);
35 return 0;
36 }
37
38 free(json_to_string(j2, JSSF_SORT | JSSF_PRETTY));
39 json_destroy(j2);
40
41 return 0;
42 }