From 0aa216ed5519d9fefb2121d33e62af8f2abf840e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 1 Nov 2016 14:15:07 -0600 Subject: [PATCH] Refactor freeing of a member_list into free_members(). --- plugins/sudoers/alias.c | 13 +------------ plugins/sudoers/gram.c | 37 +++++++++++++++++++++++-------------- plugins/sudoers/gram.y | 33 +++++++++++++++++++++------------ plugins/sudoers/parse.h | 1 + 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/plugins/sudoers/alias.c b/plugins/sudoers/alias.c index 4676a16bc..c18169ab1 100644 --- a/plugins/sudoers/alias.c +++ b/plugins/sudoers/alias.c @@ -170,21 +170,10 @@ void alias_free(void *v) { struct alias *a = (struct alias *)v; - struct member *m; - struct sudo_command *c; - void *next; debug_decl(alias_free, SUDOERS_DEBUG_ALIAS) free(a->name); - TAILQ_FOREACH_SAFE(m, &a->members, entries, next) { - if (m->type == COMMAND) { - c = (struct sudo_command *) m->name; - free(c->cmnd); - free(c->args); - } - free(m->name); - free(m); - } + free_members(&a->members); free(a); debug_return; diff --git a/plugins/sudoers/gram.c b/plugins/sudoers/gram.c index 9bd12bd8b..c34f96432 100644 --- a/plugins/sudoers/gram.c +++ b/plugins/sudoers/gram.c @@ -854,6 +854,26 @@ add_userspec(struct member *members, struct privilege *privs) debug_return_bool(true); } +/* + * Free a tailq of members but not the struct member_list container itself. + */ +void +free_members(struct member_list *members) +{ + struct member *m, *next; + struct sudo_command *c; + + TAILQ_FOREACH_SAFE(m, members, entries, next) { + if (m->type == COMMAND) { + c = (struct sudo_command *) m->name; + free(c->cmnd); + free(c->args); + } + free(m->name); + free(m); + } +} + /* * Free up space used by data structures from a previous parser run and sets * the current sudoers file to path. @@ -948,19 +968,8 @@ init_parser(const char *path, bool quiet) binding = NULL; TAILQ_FOREACH_SAFE(d, &defaults, entries, d_next) { if (d->binding != binding) { - struct member *m, *m_next; - binding = d->binding; - TAILQ_FOREACH_SAFE(m, d->binding, entries, m_next) { - if (m->type == COMMAND) { - struct sudo_command *c = - (struct sudo_command *) m->name; - free(c->cmnd); - free(c->args); - } - free(m->name); - free(m); - } + free_members(d->binding); free(d->binding); } free(d->var); @@ -994,7 +1003,7 @@ init_parser(const char *path, bool quiet) debug_return_bool(ret); } -#line 945 "gram.c" +#line 954 "gram.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ #if defined(__cplusplus) || defined(__STDC__) static int yygrowstack(void) @@ -2077,7 +2086,7 @@ case 115: } } break; -#line 2028 "gram.c" +#line 2037 "gram.c" } yyssp -= yym; yystate = *yyssp; diff --git a/plugins/sudoers/gram.y b/plugins/sudoers/gram.y index 1b087a995..38bd6104a 100644 --- a/plugins/sudoers/gram.y +++ b/plugins/sudoers/gram.y @@ -1010,6 +1010,26 @@ add_userspec(struct member *members, struct privilege *privs) debug_return_bool(true); } +/* + * Free a tailq of members but not the struct member_list container itself. + */ +void +free_members(struct member_list *members) +{ + struct member *m, *next; + struct sudo_command *c; + + TAILQ_FOREACH_SAFE(m, members, entries, next) { + if (m->type == COMMAND) { + c = (struct sudo_command *) m->name; + free(c->cmnd); + free(c->args); + } + free(m->name); + free(m); + } +} + /* * Free up space used by data structures from a previous parser run and sets * the current sudoers file to path. @@ -1104,19 +1124,8 @@ init_parser(const char *path, bool quiet) binding = NULL; TAILQ_FOREACH_SAFE(d, &defaults, entries, d_next) { if (d->binding != binding) { - struct member *m, *m_next; - binding = d->binding; - TAILQ_FOREACH_SAFE(m, d->binding, entries, m_next) { - if (m->type == COMMAND) { - struct sudo_command *c = - (struct sudo_command *) m->name; - free(c->cmnd); - free(c->args); - } - free(m->name); - free(m); - } + free_members(d->binding); free(d->binding); } free(d->var); diff --git a/plugins/sudoers/parse.h b/plugins/sudoers/parse.h index 973d0ac60..5546cd8b9 100644 --- a/plugins/sudoers/parse.h +++ b/plugins/sudoers/parse.h @@ -244,6 +244,7 @@ bool init_aliases(void); /* gram.c */ bool init_parser(const char *, bool); +void free_members(struct member_list *members); /* match_addr.c */ bool addr_matches(char *n); -- 2.40.0