/src/mosquitto/fuzzing/broker/broker_fuzz_acl_file.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 17.2k | { |
36 | 17.2k | char filename[100]; |
37 | 17.2k | FILE *fptr; |
38 | 17.2k | struct mosquitto__config config = {0}; |
39 | | |
40 | 17.2k | db.config = &config; |
41 | 17.2k | config.log_type = 0; |
42 | 17.2k | config.log_dest = 0; |
43 | | |
44 | 17.2k | umask(0077); |
45 | | |
46 | 17.2k | snprintf(filename, sizeof(filename), "/tmp/acl_file_%d", getpid()); |
47 | 17.2k | fptr = fopen(filename, "wb"); |
48 | 17.2k | if(!fptr) return 1; |
49 | 17.2k | fwrite(data, 1, size, fptr); |
50 | 17.2k | fclose(fptr); |
51 | | |
52 | 17.2k | config.security_options.acl_data.acl_file = strdup(filename); |
53 | | |
54 | 17.2k | log__init(&config); |
55 | 17.2k | mosquitto_security_init_default(); |
56 | 17.2k | mosquitto_security_cleanup_default(); |
57 | 17.2k | config__cleanup(&config); |
58 | | |
59 | 17.2k | unlink(filename); |
60 | | |
61 | 17.2k | return 0; |
62 | 17.2k | } |