/src/mosquitto/fuzzing/broker/broker_fuzz_acl_file.cpp
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2024 Roger Light <roger@atchoo.org> |
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 | | #include <cstdio> |
20 | | #include <cstdint> |
21 | | #include <cstdlib> |
22 | | #include <cstring> |
23 | | #include <sys/stat.h> |
24 | | #include <unistd.h> |
25 | | |
26 | | /* |
27 | | * Broker check of acl file |
28 | | */ |
29 | | extern "C" { |
30 | | #include "mosquitto_broker_internal.h" |
31 | | } |
32 | | |
33 | | |
34 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
35 | 18.5k | { |
36 | 18.5k | char filename[100]; |
37 | 18.5k | FILE *fptr; |
38 | 18.5k | struct mosquitto__config config = {0}; |
39 | | |
40 | 18.5k | db.config = &config; |
41 | 18.5k | config.log_type = 0; |
42 | 18.5k | config.log_dest = 0; |
43 | | |
44 | 18.5k | umask(0077); |
45 | | |
46 | 18.5k | snprintf(filename, sizeof(filename), "/tmp/acl_file_%d", getpid()); |
47 | 18.5k | fptr = fopen(filename, "wb"); |
48 | 18.5k | if(!fptr){ |
49 | 0 | return 1; |
50 | 0 | } |
51 | 18.5k | fwrite(data, 1, size, fptr); |
52 | 18.5k | fclose(fptr); |
53 | | |
54 | 18.5k | config.security_options.acl_data.acl_file = strdup(filename); |
55 | | |
56 | 18.5k | log__init(&config); |
57 | 18.5k | mosquitto_security_init_default(); |
58 | 18.5k | mosquitto_security_cleanup_default(); |
59 | 18.5k | config__cleanup(&config); |
60 | | |
61 | 18.5k | unlink(filename); |
62 | | |
63 | 18.5k | return 0; |
64 | 18.5k | } |