Coverage Report

Created: 2026-08-31 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libsmartcols/src/fuzz.c
Line
Count
Source
1
#include "fuzz.h"
2
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
7
#include "libsmartcols.h"
8
9
static void process_string(const char *str)
10
970
{
11
970
  struct libscols_filter *fltr = scols_new_filter(str);
12
13
970
  scols_unref_filter(fltr);
14
970
}
15
16
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
17
980
{
18
980
  char *str;
19
20
980
  if (size > 4096)
21
10
    return 0;
22
23
970
  str = malloc(size + 1);
24
970
  if (!str)
25
0
    return 0;
26
27
970
  memcpy(str, data, size);
28
970
  str[size] = '\0';
29
30
970
  process_string(str);
31
32
970
  free(str);
33
970
  return 0;
34
970
}
35
36
#ifndef FUZZ_TARGET
37
int main(int argc, char **argv)
38
{
39
  for (int i = 1; i < argc; i++) {
40
    FILE *f = fopen(argv[i], "r");
41
    char *buf;
42
    long len;
43
    size_t n;
44
45
    if (!f)
46
      continue;
47
    fseek(f, 0, SEEK_END);
48
    len = ftell(f);
49
    fseek(f, 0, SEEK_SET);
50
    if (len < 0) {
51
      fclose(f);
52
      continue;
53
    }
54
    buf = malloc(len + 1);
55
    if (!buf) {
56
      fclose(f);
57
      continue;
58
    }
59
    n = fread(buf, 1, len, f);
60
    fclose(f);
61
    buf[n] = '\0';
62
    process_string(buf);
63
    free(buf);
64
  }
65
  return 0;
66
}
67
#endif