diff options
Diffstat (limited to 'libselinux/utils/sefcontext_compile.c')
-rw-r--r-- | libselinux/utils/sefcontext_compile.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/libselinux/utils/sefcontext_compile.c b/libselinux/utils/sefcontext_compile.c index 33a4a424..03bc0a7e 100644 --- a/libselinux/utils/sefcontext_compile.c +++ b/libselinux/utils/sefcontext_compile.c @@ -29,11 +29,10 @@ static int process_file(struct saved_data *data, const char *filename) line_num = 0; while ((len = getline(&line_buf, &line_len, context_file)) != -1) { - char *context; - char *mode; - char *regex; + char *context = NULL; + char *mode = NULL; + char *regex = NULL; char *cp, *anchored_regex; - char *buf_p; pcre *re; pcre_extra *sd; const char *err; @@ -41,23 +40,20 @@ static int process_file(struct saved_data *data, const char *filename) size_t regex_len; int32_t stem_id; - len = strlen(line_buf); - if (line_buf[len - 1] == '\n') - line_buf[len - 1] = 0; - buf_p = line_buf; - while (isspace(*buf_p)) - buf_p++; - /* Skip comment lines and empty lines. */ - if (*buf_p == '#' || *buf_p == 0) - continue; + line_num++; - items = sscanf(line_buf, "%ms %ms %ms", ®ex, &mode, &context); - if (items < 2 || items > 3) { - fprintf(stderr, "invalid entry, skipping:%s", line_buf); - continue; - } + items = read_spec_entries(line_buf, 3, ®ex, &mode, &context); + if (items < 0) + return -1; - if (items == 2) { + if (items == 0) + continue; + else if (items == 1) { + fprintf(stderr, + "line: %u has invalid entry - skipping: %s\n", + line_num, line_buf); + continue; + } else if (items == 2) { context = mode; mode = NULL; } @@ -115,7 +111,6 @@ static int process_file(struct saved_data *data, const char *filename) free(anchored_regex); spec->sd = sd; - line_num++; data->nspec++; } |