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