From 899add50a9ab6ad963b3f849c033326fb95866da Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 2 May 2023 13:27:17 -0600 Subject: Add reset_parser() and use in place of init_parser(NULL). --- plugins/sudoers/gram.c | 6 ++++++ plugins/sudoers/gram.y | 6 ++++++ plugins/sudoers/parse.h | 1 + plugins/sudoers/regress/fuzz/fuzz_sudoers.c | 2 +- plugins/sudoers/sudoers.c | 10 +++++----- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/sudoers/gram.c b/plugins/sudoers/gram.c index 5cbdaca34..f1d784839 100644 --- a/plugins/sudoers/gram.c +++ b/plugins/sudoers/gram.c @@ -4007,6 +4007,12 @@ init_parser(const char *file) return init_parser_ext(file, NULL, false, 1); } +bool +reset_parser(void) +{ + return init_parser_ext(NULL, NULL, false, 1); +} + /* * Initialize all options in a cmndspec. */ diff --git a/plugins/sudoers/gram.y b/plugins/sudoers/gram.y index 54b9d84e9..b72eb091c 100644 --- a/plugins/sudoers/gram.y +++ b/plugins/sudoers/gram.y @@ -1824,6 +1824,12 @@ init_parser(const char *file) return init_parser_ext(file, NULL, false, 1); } +bool +reset_parser(void) +{ + return init_parser_ext(NULL, NULL, false, 1); +} + /* * Initialize all options in a cmndspec. */ diff --git a/plugins/sudoers/parse.h b/plugins/sudoers/parse.h index 36902b061..74cf0602b 100644 --- a/plugins/sudoers/parse.h +++ b/plugins/sudoers/parse.h @@ -374,6 +374,7 @@ extern struct sudoers_parse_tree parsed_policy; extern bool (*sudoers_error_hook)(const char *file, int line, int column, const char *fmt, va_list args); bool init_parser(const char *file); bool init_parser_ext(const char *file, const char *path, bool strict, int verbose); +bool reset_parser(void); void free_member(struct member *m); void free_members(struct member_list *members); void free_cmndspec(struct cmndspec *cs, struct cmndspec_list *csl); diff --git a/plugins/sudoers/regress/fuzz/fuzz_sudoers.c b/plugins/sudoers/regress/fuzz/fuzz_sudoers.c index 602db6111..61f913c62 100644 --- a/plugins/sudoers/regress/fuzz/fuzz_sudoers.c +++ b/plugins/sudoers/regress/fuzz/fuzz_sudoers.c @@ -398,7 +398,7 @@ done: /* Cleanup. */ fclose(fp); free_parse_tree(&parse_tree); - init_parser(NULL); + reset_parser(); if (sudo_user.pw != NULL) sudo_pw_delref(sudo_user.pw); if (runas_pw != NULL) diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 6aea73dd6..15a476439 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -251,7 +251,7 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[]) } /* Open and parse sudoers, set global defaults. */ - init_parser(NULL); + reset_parser(); TAILQ_FOREACH_SAFE(nss, snl, entries, nss_next) { if (nss->open(nss) == -1 || (nss->parse_tree = nss->parse(nss)) == NULL) { TAILQ_REMOVE(snl, nss, entries); @@ -846,7 +846,7 @@ done: if (def_group_plugin) group_plugin_unload(); - init_parser(NULL); + reset_parser(); if (ret == -1) { /* Free stashed copy of the environment. */ @@ -906,7 +906,7 @@ done: if (def_group_plugin) group_plugin_unload(); - init_parser(NULL); + reset_parser(); env_init(NULL); if (!rewind_perms()) @@ -975,7 +975,7 @@ done: } if (def_group_plugin) group_plugin_unload(); - init_parser(NULL); + reset_parser(); env_init(NULL); if (!rewind_perms()) @@ -2006,7 +2006,7 @@ sudoers_cleanup(void) nss->close(nss); } snl = NULL; - init_parser(NULL); + reset_parser(); } while ((def = TAILQ_FIRST(&initial_defaults)) != NULL) { TAILQ_REMOVE(&initial_defaults, def, entries); -- cgit v1.2.1