Coverage Report

Created: 2026-01-13 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mosquitto/fuzzing/broker/broker_fuzz_proxy_v1.cpp
Line
Count
Source
1
/*
2
Copyright (c) 2025 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
static const uint8_t *packet_data = NULL;
27
static int packet_data_pos = 0;
28
static int packet_data_remaining = 0;
29
30
extern "C" {
31
#include "mosquitto_broker_internal.h"
32
33
ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count)
34
5.04k
{
35
5.04k
  int res = count < packet_data_remaining?count:packet_data_remaining;
36
5.04k
  memcpy(buf, &packet_data[packet_data_pos], res);
37
5.04k
  packet_data_remaining -= res;
38
5.04k
  return res;
39
5.04k
}
40
41
int net__socket_get_address(mosq_sock_t sock, char *buf, size_t len, uint16_t *remote_port)
42
0
{
43
0
  snprintf(buf, len, "localhost");
44
0
  *remote_port = 1883;
45
0
  return MOSQ_ERR_SUCCESS;
46
0
}
47
48
int http__context_init(struct mosquitto *context)
49
0
{
50
0
  context->transport = mosq_t_http;
51
52
0
  return MOSQ_ERR_SUCCESS;
53
0
}
54
55
int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...)
56
11.1M
{
57
11.1M
  return MOSQ_ERR_SUCCESS;
58
11.1M
}
59
60
}
61
62
63
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
64
624
{
65
624
  struct mosquitto context{};
66
624
  struct mosquitto__listener listener{};
67
68
624
  packet_data = data;
69
624
  packet_data_pos = 0;
70
624
  packet_data_remaining = size;
71
72
624
  context.listener = &listener;
73
624
  context.proxy.cmd = -1;
74
624
  context.transport = mosq_t_proxy_v1;
75
76
783
  while(packet_data_remaining > 0 && context.transport != mosq_t_tcp){
77
624
    int rc = proxy_v1__read(&context);
78
624
    if(rc){
79
465
      break;
80
465
    }
81
624
  }
82
624
  free(context.address);
83
624
  free(context.proxy.buf);
84
624
  free(context.proxy.tls_version);
85
624
  free(context.proxy.cipher);
86
87
624
  return 0;
88
624
}