Line  | Count  | Source  | 
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  | 1.73k  | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 
31  | 1.73k  |   pool *p = NULL;  | 
32  | 1.73k  |   char *text = NULL;  | 
33  | 1.73k  |   const char *large_text, *malformed_text, *nested_text;  | 
34  | 1.73k  |   pr_json_object_t *json = NULL;  | 
35  |  |  | 
36  | 1.73k  |   text = (char *) malloc(size + 1);  | 
37  | 1.73k  |   if (text == NULL) { | 
38  | 0  |     return 0;  | 
39  | 0  |   }  | 
40  |  |  | 
41  | 1.73k  |   memcpy(text, data, size);  | 
42  | 1.73k  |   text[size] = '\0';  | 
43  |  |  | 
44  | 1.73k  |   p = make_sub_pool(NULL);  | 
45  | 1.73k  |   if (p == NULL) { | 
46  | 0  |     free(text);  | 
47  | 0  |     return 0;  | 
48  | 0  |   }  | 
49  |  |  | 
50  | 1.73k  |   init_json();  | 
51  |  |  | 
52  | 1.73k  |   json = pr_json_object_from_text(p, text);  | 
53  | 1.73k  |   pr_json_object_free(json);  | 
54  |  |  | 
55  | 1.73k  |   malformed_text = "{\"key\": \"value\",}"; | 
56  | 1.73k  |   json = pr_json_object_from_text(p, malformed_text);  | 
57  | 1.73k  |   pr_json_object_free(json);  | 
58  |  |  | 
59  | 1.73k  |   large_text = "{\"key\": \"value\", \"key2\": \"value2\", \"key3\": \"value3\", \"key4\": \"value4\"}"; | 
60  | 1.73k  |   json = pr_json_object_from_text(p, large_text);  | 
61  | 1.73k  |   pr_json_object_free(json);  | 
62  |  |  | 
63  | 1.73k  |   nested_text = "{\"key\": {\"subkey\": {\"subsubkey\": {\"subsubsubkey\": \"value\"}}}}"; | 
64  | 1.73k  |   json = pr_json_object_from_text(p, nested_text);  | 
65  | 1.73k  |   pr_json_object_free(json);  | 
66  |  |  | 
67  |  |   /* Provide deliberately invalid UTF-8 sequences as input now. */  | 
68  | 1.73k  |   malformed_text = "{\"key\": \"\x80\x81\x82\"}"; | 
69  | 1.73k  |   json = pr_json_object_from_text(p, malformed_text);  | 
70  | 1.73k  |   pr_json_object_free(json);  | 
71  |  |  | 
72  | 1.73k  |   finish_json();  | 
73  | 1.73k  |   destroy_pool(p);  | 
74  |  |  | 
75  | 1.73k  |   free(text);  | 
76  | 1.73k  |   return 0;  | 
77  | 1.73k  | }  |