]> granicus.if.org Git - sudo/commitdiff
Do not leak old istack if realloc fails; found by cppcheck.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 13 Jan 2014 16:52:41 +0000 (09:52 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 13 Jan 2014 16:52:41 +0000 (09:52 -0700)
Also modify yyless() to avoid a harmless cppcheck warning every
time it is used.

plugins/sudoers/toke.c
plugins/sudoers/toke.l

index e31badf1001eef83e0b282e0a839858dd75895dd..074e54a990d918c51d109d230ddd5106fb9a0a3d 100644 (file)
@@ -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) {
index aa459d9057ecf8ea26a134a54bc6c495a24e046b..438bb12a76ee66e6f26184f3a7571b923c309803 100644 (file)
@@ -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) {