1 /*
2  * DPP URI fuzzer
3  * Copyright (c) 2020, 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 
11 #include "utils/common.h"
12 #include "common/dpp.h"
13 #include "../fuzzer-common.h"
14 
15 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)16 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17 {
18 	struct dpp_global *dpp;
19 	struct dpp_global_config config;
20 	struct dpp_bootstrap_info *bi;
21 	char *uri;
22 	char buf[1000];
23 	int ret = -1;
24 
25 	wpa_fuzzer_set_debug_level();
26 
27 	if (os_program_init())
28 		return 0;
29 
30 	uri = os_malloc(size + 1);
31 	if (!uri)
32 		goto out;
33 	os_memcpy(uri, data, size);
34 	uri[size] = '\0';
35 	os_memset(&config, 0, sizeof(config));
36 	dpp = dpp_global_init(&config);
37 	if (!dpp)
38 		goto out;
39 
40 	bi = dpp_add_qr_code(dpp, uri);
41 	if (bi && dpp_bootstrap_info(dpp, bi->id, buf, sizeof(buf)) > 0)
42 		wpa_printf(MSG_DEBUG, "DPP: %s", buf);
43 	dpp_global_deinit(dpp);
44 
45 	ret = 0;
46 out:
47 	os_free(uri);
48 	os_program_deinit();
49 
50 	return ret;
51 }
52