From: Todd C. Miller Date: Sat, 13 Jun 2015 14:13:48 +0000 (-0600) Subject: Move pattern length check until after we have initialized the glob_t X-Git-Tag: SUDO_1_8_14^2~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f43f53098732de5f4667e01aec37dfa9cc551b61;p=sudo Move pattern length check until after we have initialized the glob_t so we can call globfree() even on error. From Frank Denis. --- diff --git a/lib/util/glob.c b/lib/util/glob.c index 1cb0574cc..8d4f262d2 100644 --- a/lib/util/glob.c +++ b/lib/util/glob.c @@ -203,9 +203,6 @@ sudo_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), Char *bufnext, *bufend, patbuf[PATH_MAX]; struct glob_lim limit = { 0, 0, 0 }; - if (strnlen(pattern, PATH_MAX) == PATH_MAX) - return GLOB_NOMATCH; - patnext = (unsigned char *) pattern; if (!(flags & GLOB_APPEND)) { pglob->gl_pathc = 0; @@ -222,6 +219,9 @@ sudo_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1) return GLOB_NOSPACE; + if (strnlen(pattern, PATH_MAX) == PATH_MAX) + return GLOB_NOMATCH; + bufnext = patbuf; bufend = bufnext + PATH_MAX - 1; if (flags & GLOB_NOESCAPE)