Coverage Report

Created: 2025-11-07 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mosquitto/fuzzing/plugins/dynamic-security/dynsec_fuzz_load.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
#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
5.78k
{
46
5.78k
  struct mosquitto_plugin_id_t identifier;
47
5.78k
  struct mosquitto_opt options[1];
48
49
5.78k
  db.config = (struct mosquitto__config *)calloc(1, sizeof(struct mosquitto__config));
50
5.78k
  log__init(db.config);
51
52
5.78k
  memset(&identifier, 0, sizeof(identifier));
53
54
5.78k
  options[0].key = strdup("config_file");
55
5.78k
  options[0].value = filename;
56
57
5.78k
  mosquitto_plugin_init(&identifier, NULL, options, 1);
58
5.78k
  mosquitto_plugin_cleanup(NULL, options, 1);
59
60
5.78k
  free(options[0].key);
61
5.78k
  free(db.config);
62
5.78k
  free(identifier.plugin_name);
63
5.78k
  free(identifier.plugin_version);
64
5.78k
  db.config = NULL;
65
5.78k
}
66
67
68
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
69
17.8k
{
70
17.8k
  char filename[100];
71
17.8k
  FILE *fptr;
72
73
17.8k
  umask(0077);
74
75
17.8k
  snprintf(filename, sizeof(filename), "/tmp/dynsec%d.conf", getpid());
76
17.8k
  fptr = fopen(filename, "wb");
77
17.8k
  if(!fptr){
78
0
    return 1;
79
0
  }
80
17.8k
  fwrite(data, 1, size, fptr);
81
17.8k
  fclose(fptr);
82
83
17.8k
  run_dynsec(filename);
84
85
17.8k
  unlink(filename);
86
87
17.8k
  return 0;
88
17.8k
}