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_v2.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 http__context_init(struct mosquitto *context)
42
0
{
43
0
  context->transport = mosq_t_http;
44
45
0
  return MOSQ_ERR_SUCCESS;
46
0
}
47
48
int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...)
49
11.1M
{
50
11.1M
  return MOSQ_ERR_SUCCESS;
51
11.1M
}
52
53
}
54
55
56
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
57
624
{
58
624
  struct mosquitto context{};
59
624
  struct mosquitto__listener listener{};
60
61
624
  packet_data = data;
62
624
  packet_data_pos = 0;
63
624
  packet_data_remaining = size;
64
65
624
  context.listener = &listener;
66
624
  context.proxy.cmd = -1;
67
624
  context.transport = mosq_t_proxy_v2;
68
69
783
  while(packet_data_remaining > 0 && context.transport != mosq_t_tcp){
70
624
    int rc = proxy_v2__read(&context);
71
624
    if(rc){
72
465
      break;
73
465
    }
74
624
  }
75
624
  free(context.address);
76
624
  free(context.proxy.buf);
77
624
  free(context.proxy.tls_version);
78
624
  free(context.proxy.cipher);
79
80
624
  return 0;
81
624
}