Coverage Report

Created: 2026-04-20 06:19

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