Line | Count | Source |
1 | | /* |
2 | | * ProFTPD - FTP server fuzzing testsuite |
3 | | * Copyright (c) 2021-2026 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, see <https://www.gnu.org/licenses/>. |
17 | | * |
18 | | * As a special exemption, The ProFTPD Project team and other respective |
19 | | * copyright holders give permission to link this program with OpenSSL, and |
20 | | * distribute the resulting executable, without including the source code for |
21 | | * OpenSSL in the source distribution. |
22 | | */ |
23 | | |
24 | | #include <stdint.h> |
25 | | #include <string.h> |
26 | | #include <stdlib.h> |
27 | | #include "json.h" |
28 | | |
29 | 1.71k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
30 | 1.71k | pool *p = NULL; |
31 | 1.71k | char *text = NULL; |
32 | 1.71k | const char *large_text, *malformed_text, *nested_text; |
33 | 1.71k | pr_json_object_t *json = NULL; |
34 | | |
35 | 1.71k | text = (char *) malloc(size + 1); |
36 | 1.71k | if (text == NULL) { |
37 | 0 | return 0; |
38 | 0 | } |
39 | | |
40 | 1.71k | memcpy(text, data, size); |
41 | 1.71k | text[size] = '\0'; |
42 | | |
43 | 1.71k | p = make_sub_pool(NULL); |
44 | 1.71k | if (p == NULL) { |
45 | 0 | free(text); |
46 | 0 | return 0; |
47 | 0 | } |
48 | | |
49 | 1.71k | init_json(); |
50 | | |
51 | 1.71k | json = pr_json_object_from_text(p, text); |
52 | 1.71k | pr_json_object_free(json); |
53 | | |
54 | 1.71k | malformed_text = "{\"key\": \"value\",}"; |
55 | 1.71k | json = pr_json_object_from_text(p, malformed_text); |
56 | 1.71k | pr_json_object_free(json); |
57 | | |
58 | 1.71k | large_text = "{\"key\": \"value\", \"key2\": \"value2\", \"key3\": \"value3\", \"key4\": \"value4\"}"; |
59 | 1.71k | json = pr_json_object_from_text(p, large_text); |
60 | 1.71k | pr_json_object_free(json); |
61 | | |
62 | 1.71k | nested_text = "{\"key\": {\"subkey\": {\"subsubkey\": {\"subsubsubkey\": \"value\"}}}}"; |
63 | 1.71k | json = pr_json_object_from_text(p, nested_text); |
64 | 1.71k | pr_json_object_free(json); |
65 | | |
66 | | /* Provide deliberately invalid UTF-8 sequences as input now. */ |
67 | 1.71k | malformed_text = "{\"key\": \"\x80\x81\x82\"}"; |
68 | 1.71k | json = pr_json_object_from_text(p, malformed_text); |
69 | 1.71k | pr_json_object_free(json); |
70 | | |
71 | 1.71k | finish_json(); |
72 | 1.71k | destroy_pool(p); |
73 | | |
74 | 1.71k | free(text); |
75 | 1.71k | return 0; |
76 | 1.71k | } |