From b75bb6991fb3dae273a2b9f068e2a7ca875c88c1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 13 Jan 2014 09:52:41 -0700 Subject: [PATCH] Do not leak old istack if realloc fails; found by cppcheck. Also modify yyless() to avoid a harmless cppcheck warning every time it is used. --- plugins/sudoers/toke.c | 9 ++++++--- plugins/sudoers/toke.l | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/sudoers/toke.c b/plugins/sudoers/toke.c index e31badf10..074e54a99 100644 --- a/plugins/sudoers/toke.c +++ b/plugins/sudoers/toke.c @@ -148,7 +148,7 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ *yy_cp = yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + yy_cp = yy_bp + n - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) @@ -4147,18 +4147,21 @@ _push_include(char *path, bool isdir) /* push current state onto stack */ if (idepth >= istacksize) { + struct include_stack *new_istack; + if (idepth > MAX_SUDOERS_DEPTH) { sudoerserror(N_("too many levels of includes")); debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; - istack = (struct include_stack *) realloc(istack, + new_istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); - if (istack == NULL) { + if (new_istack == NULL) { warning(NULL); sudoerserror(NULL); debug_return_bool(false); } + istack = new_istack; } SLIST_INIT(&istack[idepth].more); if (isdir) { diff --git a/plugins/sudoers/toke.l b/plugins/sudoers/toke.l index aa459d905..438bb12a7 100644 --- a/plugins/sudoers/toke.l +++ b/plugins/sudoers/toke.l @@ -888,18 +888,21 @@ _push_include(char *path, bool isdir) /* push current state onto stack */ if (idepth >= istacksize) { + struct include_stack *new_istack; + if (idepth > MAX_SUDOERS_DEPTH) { sudoerserror(N_("too many levels of includes")); debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; - istack = (struct include_stack *) realloc(istack, + new_istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); - if (istack == NULL) { + if (new_istack == NULL) { warning(NULL); sudoerserror(NULL); debug_return_bool(false); } + istack = new_istack; } SLIST_INIT(&istack[idepth].more); if (isdir) { -- 2.40.0