| 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 |
#include <cstdio> |
| 20 |
#include <cstdint> |
| 21 |
#include <cstdlib> |
| 22 |
#include <cstring> |
| 23 |
#include <sys/stat.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#ifdef __cplusplus |
| 27 |
extern "C" { |
| 28 |
#endif |
| 29 |
|
| 30 |
#include <mosquitto.h> |
| 31 |
#include <mosquitto_broker_internal.h> |
| 32 |
|
| 33 |
#ifdef __cplusplus |
| 34 |
} |
| 35 |
#endif |
| 36 |
|
| 37 |
/* |
| 38 |
* Test loading a file |
| 39 |
*/ |
| 40 |
|
| 41 |
extern struct mosquitto_db db; |
| 42 |
|
| 43 |
|
| 44 |
void run_dynsec(char *filename) |
| 45 |
{ |
| 46 |
struct mosquitto_plugin_id_t identifier; |
| 47 |
struct mosquitto_opt options[1]; |
| 48 |
|
| 49 |
db.config = (struct mosquitto__config *)calloc(1, sizeof(struct mosquitto__config)); |
| 50 |
log__init(db.config); |
| 51 |
|
| 52 |
memset(&identifier, 0, sizeof(identifier)); |
| 53 |
|
| 54 |
options[0].key = strdup("config_file"); |
| 55 |
options[0].value = filename; |
| 56 |
|
| 57 |
mosquitto_plugin_init(&identifier, NULL, options, 1); |
| 58 |
mosquitto_plugin_cleanup(NULL, options, 1); |
| 59 |
|
| 60 |
free(options[0].key); |
| 61 |
free(db.config); |
| 62 |
free(identifier.plugin_name); |
| 63 |
free(identifier.plugin_version); |
| 64 |
db.config = NULL; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 69 |
{ |
| 70 |
char filename[100]; |
| 71 |
FILE *fptr; |
| 72 |
|
| 73 |
umask(0077); |
| 74 |
|
| 75 |
snprintf(filename, sizeof(filename), "/tmp/dynsec%d.conf", getpid()); |
| 76 |
fptr = fopen(filename, "wb"); |
| 77 |
if(!fptr){ |
| 78 |
return 1; |
| 79 |
} |
| 80 |
fwrite(data, 1, size, fptr); |
| 81 |
fclose(fptr); |
| 82 |
|
| 83 |
run_dynsec(filename); |
| 84 |
|
| 85 |
unlink(filename); |
| 86 |
|
| 87 |
return 0; |
| 88 |
} |