Coverage Report

Created: 2026-08-03 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_alg_ses_des.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
215
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9
215
  FuzzedDataProvider fuzzed_data(data, size);
10
215
  u_int16_t i, num_iteration;
11
215
  struct ndpi_ses_struct s;
12
215
  struct ndpi_des_struct d;
13
215
  int rc_ses, rc_des;
14
215
  double forecast, confidence_band, *values, value;
15
215
  float significance, alpha_ses, alpha_des, beta;
16
17
  /* Just to have some data */
18
215
  if(fuzzed_data.remaining_bytes() < 2048)
19
20
    return -1;
20
21
  /* To allow memory allocation failures */
22
195
  fuzz_set_alloc_callbacks_and_seed(size);
23
24
  /* Training */
25
195
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
26
195
  values = (double *)ndpi_malloc(sizeof(double) * num_iteration);
27
195
  if (!values)
28
3
    return 0;
29
12.7k
  for (i = 0; i < num_iteration; i++)
30
12.5k
    values[i] = fuzzed_data.ConsumeFloatingPoint<double>();
31
192
  ndpi_ses_fitting(values, num_iteration, &alpha_ses);
32
192
  ndpi_des_fitting(values, num_iteration, &alpha_des, &beta);
33
192
  ndpi_free(values);
34
35
192
  significance = fuzzed_data.ConsumeFloatingPointInRange<float>(0, 1.1);
36
192
  rc_ses = ndpi_ses_init(fuzzed_data.ConsumeBool() ? &s : NULL, alpha_ses, significance);
37
192
  rc_des = ndpi_des_init(fuzzed_data.ConsumeBool() ? &d : NULL, alpha_des, beta, significance);
38
39
192
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
40
11.3k
  for (i = 0; i < num_iteration; i++) {
41
11.2k
    value = fuzzed_data.ConsumeFloatingPoint<double>();
42
11.2k
    if (rc_ses == 0)
43
6.45k
      ndpi_ses_add_value(&s, value, &forecast, &confidence_band);
44
11.2k
    if (rc_des == 0)
45
6.76k
      ndpi_des_add_value(&d, value, &forecast, &confidence_band);
46
11.2k
  }
47
48
192
  ndpi_ses_reset(&s);
49
192
  ndpi_des_reset(&d);
50
51
192
  return 0;
52
195
}