From: Todd C. Miller Date: Fri, 30 Mar 2018 00:53:53 +0000 (-0600) Subject: Avoid NULL deref in an error path. CID 183467 X-Git-Tag: SUDO_1_8_23^2~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbd5613b1a5ba56b70e0824020c7a432d373b0cd;p=sudo Avoid NULL deref in an error path. CID 183467 --- diff --git a/plugins/sudoers/cvtsudoers.c b/plugins/sudoers/cvtsudoers.c index 2c78659ba..61ebb2173 100644 --- a/plugins/sudoers/cvtsudoers.c +++ b/plugins/sudoers/cvtsudoers.c @@ -584,8 +584,10 @@ cvtsudoers_string_alloc(const char *s) void cvtsudoers_string_free(struct cvtsudoers_string *ls) { - free(ls->str); - free(ls); + if (ls != NULL) { + free(ls->str); + free(ls); + } } struct cvtsudoers_str_list * @@ -595,8 +597,10 @@ str_list_alloc(void) debug_decl(str_list_alloc, SUDOERS_DEBUG_UTIL) strlist = malloc(sizeof(*strlist)); - STAILQ_INIT(strlist); - strlist->refcnt = 1; + if (strlist != NULL) { + STAILQ_INIT(strlist); + strlist->refcnt = 1; + } debug_return_ptr(strlist); } @@ -608,12 +612,14 @@ str_list_free(void *v) struct cvtsudoers_string *first; debug_decl(str_list_free, SUDOERS_DEBUG_UTIL) - if (--strlist->refcnt == 0) { - while ((first = STAILQ_FIRST(strlist)) != NULL) { - STAILQ_REMOVE_HEAD(strlist, entries); - cvtsudoers_string_free(first); + if (strlist != NULL) { + if (--strlist->refcnt == 0) { + while ((first = STAILQ_FIRST(strlist)) != NULL) { + STAILQ_REMOVE_HEAD(strlist, entries); + cvtsudoers_string_free(first); + } + free(strlist); } - free(strlist); } debug_return; }