Debian Codegraph @

tests/fuzzing/json_fuzzer.c

raw symbols SCIP
1 /*
2 * ProFTPD - FTP server fuzzing testsuite
3 * Copyright (c) 2021-2024 The ProFTPD Project team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25 #include <stdint.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include "json.h"
29
30 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31 pool *p = NULL;
32 char *text = NULL;
33 const char *large_text, *malformed_text, *nested_text;
34 pr_json_object_t *json = NULL;
35
36 text = (char *) malloc(size + 1);
37 if (text == NULL) {
38 return 0;
39 }
40
41 memcpy(text, data, size);
42 text[size] = '\0';
43
44 p = make_sub_pool(NULL);
45 if (p == NULL) {
46 free(text);
47 return 0;
48 }
49
50 init_json();
51
52 json = pr_json_object_from_text(p, text);
53 pr_json_object_free(json);
54
55 malformed_text = "{\"key\": \"value\",}";
56 json = pr_json_object_from_text(p, malformed_text);
57 pr_json_object_free(json);
58
59 large_text = "{\"key\": \"value\", \"key2\": \"value2\", \"key3\": \"value3\", \"key4\": \"value4\"}";
60 json = pr_json_object_from_text(p, large_text);
61 pr_json_object_free(json);
62
63 nested_text = "{\"key\": {\"subkey\": {\"subsubkey\": {\"subsubsubkey\": \"value\"}}}}";
64 json = pr_json_object_from_text(p, nested_text);
65 pr_json_object_free(json);
66
67 /* Provide deliberately invalid UTF-8 sequences as input now. */
68 malformed_text = "{\"key\": \"\x80\x81\x82\"}";
69 json = pr_json_object_from_text(p, malformed_text);
70 pr_json_object_free(json);
71
72 finish_json();
73 destroy_pool(p);
74
75 free(text);
76 return 0;
77 }