diff --git a/src/check_hooks.c b/src/check_hooks.c index 41b41a1a..ae671109 100644 --- a/src/check_hooks.c +++ b/src/check_hooks.c @@ -28,18 +28,6 @@ int found_issue = 0; int suppress_output = 0; int full_path = 0; -#define ALLOC_NODE(nl) if (ck->check_nodes[nl]) { \ - loc = ck->check_nodes[nl]; \ - while (loc->next) { loc = loc->next; } \ - loc->next = xmalloc(sizeof(struct check_node)); \ - if (!loc->next) { return SELINT_OUT_OF_MEM; } \ - loc = loc->next; \ -} else { \ - ck->check_nodes[nl] = xmalloc(sizeof(struct check_node)); \ - if (!ck->check_nodes[nl]) { return SELINT_OUT_OF_MEM; } \ - loc = ck->check_nodes[nl]; \ -} - enum selint_error add_check(enum node_flavor check_flavor, struct checks *ck, const char *check_id, struct check_result *(*check_function)(const struct check_data *check_data, @@ -47,7 +35,17 @@ enum selint_error add_check(enum node_flavor check_flavor, struct checks *ck, { struct check_node *loc; - ALLOC_NODE(check_flavor); + if (ck->check_nodes[check_flavor]) { + loc = ck->check_nodes[check_flavor]; + while (loc->next) { + loc = loc->next; + } + loc->next = xmalloc(sizeof(struct check_node)); + loc = loc->next; + } else { + ck->check_nodes[check_flavor] = xmalloc(sizeof(struct check_node)); + loc = ck->check_nodes[check_flavor]; + } loc->check_function = check_function; loc->check_id = xstrdup(check_id); diff --git a/src/ordering.c b/src/ordering.c index c9cb48b2..92854af3 100644 --- a/src/ordering.c +++ b/src/ordering.c @@ -195,6 +195,7 @@ const char *get_section(const struct policy_node *node) case NODE_SPT_FILE: case NODE_AV_FILE: case NODE_COND_FILE: + case NODE_CLEANUP: return NULL; // Should never happen case NODE_HEADER: return SECTION_NON_ORDERED; // Guaranteed at top by grammar diff --git a/src/parse_fc.c b/src/parse_fc.c index 3a4b9b0d..0f241404 100644 --- a/src/parse_fc.c +++ b/src/parse_fc.c @@ -231,7 +231,7 @@ bool check_for_fc_macro(const char *line, const struct string_list *custom_fc_ma struct policy_node *parse_fc_file(const char *filename, const struct string_list *custom_fc_macros) { - FILE *fd = fopen(filename, "r"); + FILE *fd = fopen(filename, "re"); if (!fd) { return NULL; diff --git a/src/runner.c b/src/runner.c index 3e631edd..0dcedf66 100644 --- a/src/runner.c +++ b/src/runner.c @@ -41,7 +41,7 @@ struct policy_node *parse_one_file(const char *filename, enum node_flavor flavor set_current_module_name(mod_name); free(copy); - FILE *f = fopen(filename, "r"); + FILE *f = fopen(filename, "re"); if (!f) { printf("%sError%s: Failed to open %s: %s\n", color_error(), color_reset(), filename, strerror(errno)); return NULL; diff --git a/src/startup.c b/src/startup.c index c53a7875..c717189a 100644 --- a/src/startup.c +++ b/src/startup.c @@ -77,7 +77,7 @@ enum selint_error load_access_vectors_source(const char *av_path) set_current_module_name(av_path); - FILE *f = fopen(av_path, "r"); + FILE *f = fopen(av_path, "re"); if (!f) { printf("%sError%s: Failed to open %s: %s\n", color_error(), color_reset(), av_path, strerror(errno)); return SELINT_IO_ERROR; @@ -193,7 +193,7 @@ static char *strip_space(char *str) enum selint_error load_modules_source(const char *modules_conf_path) { - FILE *fd = fopen(modules_conf_path, "r"); + FILE *fd = fopen(modules_conf_path, "re"); if (!fd) { return SELINT_IO_ERROR; @@ -242,7 +242,7 @@ enum selint_error load_modules_source(const char *modules_conf_path) enum selint_error load_obj_perm_sets_source(const char *obj_perm_sets_path) { - FILE *f = fopen(obj_perm_sets_path, "r"); + FILE *f = fopen(obj_perm_sets_path, "re"); if (!f) { return SELINT_IO_ERROR; } @@ -321,7 +321,7 @@ static enum selint_error load_global_conditions_file(const char *path) set_current_module_name("__global__"); - FILE *f = fopen(path, "r"); + FILE *f = fopen(path, "re"); if (!f) { printf("%sError%s: Failed to open file %s: %s\n", color_error(), color_reset(), path, strerror(errno)); return SELINT_IO_ERROR; diff --git a/src/util.h b/src/util.h index d2f3fd68..5e524458 100644 --- a/src/util.h +++ b/src/util.h @@ -18,6 +18,8 @@ #define UTIL_H #include +#include +#include // ignore conversions discarding const specifier, e.g. // const char [] -> char *