Coverage Report

Created: 2025-12-18 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/selinux/libsepol/fuzz/secilc-fuzzer.c
Line
Count
Source
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <stdint.h>
4
#include <string.h>
5
#include <getopt.h>
6
#include <sys/stat.h>
7
8
#include <sepol/cil/cil.h>
9
#include <sepol/policydb.h>
10
11
141
static void log_handler(__attribute__((unused)) int lvl, __attribute__((unused)) const char *msg) {
12
  /* be quiet */
13
141
}
14
15
48
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
16
48
  enum cil_log_level log_level = CIL_ERR;
17
48
  struct sepol_policy_file *pf = NULL;
18
48
  FILE *dev_null = NULL;
19
48
  int target = SEPOL_TARGET_SELINUX;
20
48
  int disable_dontaudit = 0;
21
48
  int multiple_decls = 0;
22
48
  int disable_neverallow = 0;
23
48
  int preserve_tunables = 0;
24
48
  int policyvers = POLICYDB_VERSION_MAX;
25
48
  int mls = -1;
26
48
  int attrs_expand_generated = 0;
27
48
  struct cil_db *db = NULL;
28
48
  sepol_policydb_t *pdb = NULL;
29
30
48
  cil_set_log_level(log_level);
31
48
  cil_set_log_handler(log_handler);
32
33
48
  cil_db_init(&db);
34
48
  cil_set_disable_dontaudit(db, disable_dontaudit);
35
48
  cil_set_multiple_decls(db, multiple_decls);
36
48
  cil_set_disable_neverallow(db, disable_neverallow);
37
48
  cil_set_preserve_tunables(db, preserve_tunables);
38
48
  cil_set_mls(db, mls);
39
48
  cil_set_target_platform(db, target);
40
48
  cil_set_policy_version(db, policyvers);
41
48
  cil_set_attrs_expand_generated(db, attrs_expand_generated);
42
43
48
  if (cil_add_file(db, "fuzz", (const char *)data, size) != SEPOL_OK)
44
20
    goto exit;
45
46
28
  if (cil_compile(db) != SEPOL_OK)
47
28
    goto exit;
48
49
0
  if (cil_build_policydb(db, &pdb) != SEPOL_OK)
50
0
    goto exit;
51
52
0
  if (sepol_policydb_optimize(pdb) != SEPOL_OK)
53
0
    goto exit;
54
55
0
  dev_null = fopen("/dev/null", "w");
56
0
  if (dev_null == NULL)
57
0
    goto exit;
58
59
0
  if (sepol_policy_file_create(&pf) != 0)
60
0
    goto exit;
61
62
0
  sepol_policy_file_set_fp(pf, dev_null);
63
64
0
  if (sepol_policydb_write(pdb, pf) != 0)
65
0
    goto exit;
66
48
exit:
67
48
  if (dev_null != NULL)
68
0
    fclose(dev_null);
69
70
48
  cil_db_destroy(&db);
71
48
  sepol_policydb_free(pdb);
72
48
  sepol_policy_file_free(pf);
73
48
  return 0;
74
0
}