Coverage Report

Created: 2025-07-12 06:44

/src/selinux/checkpolicy/parse_util.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Author: Karl MacMillan <kmacmillan@tresys.com>
3
 *
4
 * Copyright (C) 2006 Tresys Technology, LLC
5
 *
6
 *  This library is free software; you can redistribute it and/or
7
 *  modify it under the terms of the GNU Lesser General Public
8
 *  License as published by the Free Software Foundation; either
9
 *  version 2.1 of the License, or (at your option) any later version.
10
 *
11
 *  This library is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 *  Lesser General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Lesser General Public
17
 *  License along with this library; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
#include "parse_util.h"
22
#include "queue.h"
23
24
/* these are defined in policy_parse.y and are needed for read_source_policy */
25
extern FILE *yyin;
26
extern void init_parser(int pass, const char *input_name);
27
extern int yyparse(void);
28
extern void yyrestart(FILE *);
29
extern int yylex_destroy(void);
30
extern queue_t id_queue;
31
extern unsigned int policydb_errors;
32
extern policydb_t *policydbp;
33
extern int mlspol;
34
35
int read_source_policy(policydb_t * p, const char *file, const char *progname)
36
0
{
37
0
  int rc = -1;
38
39
0
  yyin = fopen(file, "r");
40
0
  if (!yyin) {
41
0
    fprintf(stderr, "%s:  unable to open %s:  %s\n", progname, file, strerror(errno));
42
0
    return -1;
43
0
  }
44
45
0
  id_queue = queue_create();
46
0
  if (id_queue == NULL) {
47
0
    fprintf(stderr, "%s: out of memory!\n", progname);
48
0
    goto cleanup;
49
0
  }
50
51
0
  mlspol = p->mls;
52
0
  policydbp = p;
53
0
  policydbp->name = strdup(file);
54
0
  if (!policydbp->name) {
55
0
    fprintf(stderr, "%s: out of memory!\n", progname);
56
0
    goto cleanup;
57
0
  }
58
59
0
  init_parser(1, file);
60
0
  if (yyparse() || policydb_errors) {
61
0
    fprintf(stderr,
62
0
      "%s:  error(s) encountered while parsing configuration\n",
63
0
      progname);
64
0
    goto cleanup;
65
0
  }
66
0
  rewind(yyin);
67
0
  init_parser(2, file);
68
0
  yyrestart(yyin);
69
0
  if (yyparse() || policydb_errors) {
70
0
    fprintf(stderr,
71
0
      "%s:  error(s) encountered while parsing configuration\n",
72
0
      progname);
73
0
    goto cleanup;
74
0
  }
75
76
0
  rc = 0;
77
78
0
cleanup:
79
0
  queue_destroy(id_queue);
80
0
  fclose(yyin);
81
0
  yylex_destroy();
82
83
0
  return rc;
84
0
}