/src/hostap/tests/fuzzing/json/json.c
Line | Count | Source |
1 | | /* |
2 | | * JSON parser - test program |
3 | | * Copyright (c) 2019, Jouni Malinen <j@w1.fi> |
4 | | * |
5 | | * This software may be distributed under the terms of the BSD license. |
6 | | * See README for more details. |
7 | | */ |
8 | | |
9 | | #include "utils/includes.h" |
10 | | #include "utils/common.h" |
11 | | #include "utils/json.h" |
12 | | #include "../fuzzer-common.h" |
13 | | |
14 | | |
15 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
16 | 1.05k | { |
17 | 1.05k | struct json_token *root; |
18 | 1.05k | char *txt; |
19 | 1.05k | size_t buflen = 10000; |
20 | | |
21 | 1.05k | wpa_fuzzer_set_debug_level(); |
22 | | |
23 | 1.05k | root = json_parse((const char *) data, size); |
24 | 1.05k | if (!root) { |
25 | 920 | wpa_printf(MSG_DEBUG, "JSON parsing failed"); |
26 | 920 | return 0; |
27 | 920 | } |
28 | | |
29 | 131 | txt = os_zalloc(buflen); |
30 | 131 | if (txt) { |
31 | 131 | json_print_tree(root, txt, buflen); |
32 | 131 | wpa_printf(MSG_DEBUG, "%s", txt); |
33 | 131 | os_free(txt); |
34 | 131 | } |
35 | 131 | json_free(root); |
36 | | |
37 | 131 | return 0; |
38 | 1.05k | } |