Coverage Report

Created: 2026-01-05 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_alg_hll.cpp
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "fuzz_common_code.h"
3
4
#include <stdint.h>
5
#include <stdio.h>
6
#include "fuzzer/FuzzedDataProvider.h"
7
8
209
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9
209
  FuzzedDataProvider fuzzed_data(data, size);
10
209
  u_int16_t i, num_iteration;
11
209
  struct ndpi_hll *hll;
12
209
  int rc;
13
14
  /* Just to have some data */
15
209
  if(fuzzed_data.remaining_bytes() < 2048)
16
20
    return -1;
17
18
  /* To allow memory allocation failures */
19
189
  fuzz_set_alloc_callbacks_and_seed(size);
20
21
189
  hll = (struct ndpi_hll *)ndpi_malloc(sizeof(*hll));
22
23
189
  rc = ndpi_hll_init(hll, fuzzed_data.ConsumeIntegral<u_int8_t>());
24
25
189
  if (rc == 0) {
26
166
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
27
7.50k
    for (i = 0; i < num_iteration; i++)
28
7.34k
      ndpi_hll_add_number(hll, fuzzed_data.ConsumeIntegral<u_int32_t>());
29
30
166
    ndpi_hll_count(hll);
31
32
166
    ndpi_hll_reset(hll);
33
34
166
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
35
12.6k
    for (i = 0; i < num_iteration; i++) {
36
12.4k
      std::vector<int8_t>data = fuzzed_data.ConsumeBytes<int8_t>(fuzzed_data.ConsumeIntegral<u_int8_t>());
37
12.4k
      ndpi_hll_add(hll, (char *)data.data(), data.size());
38
12.4k
    }
39
40
166
    ndpi_hll_count(hll);
41
42
166
    ndpi_hll_destroy(hll);
43
166
  }
44
45
189
  ndpi_free(hll);
46
47
189
  return 0;
48
209
}