From f43f53098732de5f4667e01aec37dfa9cc551b61 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 13 Jun 2015 08:13:48 -0600 Subject: [PATCH] Move pattern length check until after we have initialized the glob_t so we can call globfree() even on error. From Frank Denis. --- lib/util/glob.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) -- 2.50.1