Coverage Report

Created: 2025-12-20 06:28

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
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_ses_struct s;
12
209
  struct ndpi_des_struct d;
13
209
  int rc_ses, rc_des;
14
209
  double forecast, confidence_band, *values, value;
15
209
  float significance, alpha_ses, alpha_des, beta;
16
17
  /* Just to have some data */
18
209
  if(fuzzed_data.remaining_bytes() < 2048)
19
20
    return -1;
20
21
  /* To allow memory allocation failures */
22
189
  fuzz_set_alloc_callbacks_and_seed(size);
23
24
  /* Training */
25
189
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
26
189
  values = (double *)ndpi_malloc(sizeof(double) * num_iteration);
27
189
  if (!values)
28
3
    return 0;
29
12.5k
  for (i = 0; i < num_iteration; i++)
30
12.3k
    values[i] = fuzzed_data.ConsumeFloatingPoint<double>();
31
186
  ndpi_ses_fitting(values, num_iteration, &alpha_ses);
32
186
  ndpi_des_fitting(values, num_iteration, &alpha_des, &beta);
33
186
  ndpi_free(values);
34
35
186
  significance = fuzzed_data.ConsumeFloatingPointInRange<float>(0, 1.1);
36
186
  rc_ses = ndpi_ses_init(fuzzed_data.ConsumeBool() ? &s : NULL, alpha_ses, significance);
37
186
  rc_des = ndpi_des_init(fuzzed_data.ConsumeBool() ? &d : NULL, alpha_des, beta, significance);
38
39
186
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
40
12.9k
  for (i = 0; i < num_iteration; i++) {
41
12.7k
    value = fuzzed_data.ConsumeFloatingPoint<double>();
42
12.7k
    if (rc_ses == 0)
43
6.24k
      ndpi_ses_add_value(&s, value, &forecast, &confidence_band);
44
12.7k
    if (rc_des == 0)
45
6.19k
      ndpi_des_add_value(&d, value, &forecast, &confidence_band);
46
12.7k
  }
47
48
186
  ndpi_ses_reset(&s);
49
186
  ndpi_des_reset(&d);
50
51
186
  return 0;
52
189
}