/src/mosquitto/fuzzing/broker/broker_fuzz_handle_connect.cpp
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2023 Cedalo GmbH |
3 | | |
4 | | All rights reserved. This program and the accompanying materials |
5 | | are made available under the terms of the Eclipse Public License 2.0 |
6 | | and Eclipse Distribution License v1.0 which accompany this distribution. |
7 | | |
8 | | The Eclipse Public License is available at |
9 | | https://www.eclipse.org/legal/epl-2.0/ |
10 | | and the Eclipse Distribution License is available at |
11 | | http://www.eclipse.org/org/documents/edl-v10.php. |
12 | | |
13 | | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
14 | | |
15 | | Contributors: |
16 | | Roger Light - initial implementation and documentation. |
17 | | */ |
18 | | |
19 | | #define kMaxInputLength 100000 |
20 | | #include "fuzz_packet_read_base.h" |
21 | | |
22 | | |
23 | | extern "C" int fuzz_basic_auth(int event, void *event_data, void *userdata) |
24 | 0 | { |
25 | 0 | struct mosquitto_evt_basic_auth *ed = (struct mosquitto_evt_basic_auth *)event_data; |
26 | | |
27 | | /* This is a check that is ultimately determined by the fuzz input data, so |
28 | | * the fuzzer can discover how to access both the fail/success cases. |
29 | | */ |
30 | 0 | if(ed->client->id && (ed->client->id[0]%2 == 0)){ |
31 | 0 | return MOSQ_ERR_SUCCESS; |
32 | 0 | }else{ |
33 | 0 | return MOSQ_ERR_AUTH; |
34 | 0 | } |
35 | 0 | } |
36 | | |
37 | | |
38 | | extern "C" int fuzz_packet_read_init(struct mosquitto *context) |
39 | 5.96k | { |
40 | 5.96k | context->listener->security_options->pid = (mosquitto_plugin_id_t *)calloc(1, sizeof(mosquitto_plugin_id_t)); |
41 | 5.96k | if(!context->listener->security_options->pid){ |
42 | 0 | return 1; |
43 | 0 | } |
44 | 5.96k | mosquitto_callback_register(context->listener->security_options->pid, |
45 | 5.96k | MOSQ_EVT_BASIC_AUTH, fuzz_basic_auth, NULL, NULL); |
46 | | |
47 | 5.96k | return 0; |
48 | 5.96k | } |
49 | | |
50 | | |
51 | | extern "C" void fuzz_packet_read_cleanup(struct mosquitto *context) |
52 | 7.67k | { |
53 | 7.67k | mosquitto_callback_unregister(context->listener->security_options->pid, |
54 | 7.67k | MOSQ_EVT_BASIC_AUTH, fuzz_basic_auth, NULL); |
55 | | |
56 | 7.67k | free(context->listener->security_options->pid); |
57 | 7.67k | context->listener->security_options->pid = NULL; |
58 | 7.67k | } |
59 | | |
60 | | |
61 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
62 | 8.30k | { |
63 | 8.30k | return fuzz_packet_read_base(data, size, handle__connect); |
64 | 8.30k | } |