diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-03-19 19:26:06 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-03-22 05:46:47 +0100 |
commit | 1a3d22af2606aceb8e175c318e8632a2030318e4 (patch) | |
tree | 8ac894ddf80e6d337b80d9ac1e39f7879a55db95 /lib | |
parent | 9d5beb677dd65647e9cba299e558306c6c4bc8c1 (diff) | |
download | barebox-1a3d22af2606aceb8e175c318e8632a2030318e4.tar.gz |
glob: use empty globfree when compiling without CONFIG_GLOB
We already return an error code unconditionally when building with
!CONFIG_GLOB. We need to do the same for globfree. Otherwise,
we run risk of corrupting memory.
This issue exists since the code was first added, but it became
more acute with 90cde3b9ff46 ("startup: Execute init scripts in
alphabetical order"), which added a globfree into the shell init.
Configuration without CONFIG_GLOB would from then on experience
memory corruption during startup.
Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/glob.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/glob.c b/lib/glob.c index 32f7afdce8..8523bad9a7 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -406,6 +406,18 @@ static int glob_in_dir(const char *pattern, const char *directory, } return nfound == 0 ? GLOB_NOMATCH : 0; } + +/* Free storage allocated in PGLOB by a previous `glob' call. */ +void globfree(glob_t *pglob) +{ + if (pglob->gl_pathv != NULL) { + int i = pglob->gl_flags & GLOB_DOOFFS ? pglob->gl_offs : 0; + for (; i < pglob->gl_pathc; ++i) + if (pglob->gl_pathv[i] != NULL) + free((__ptr_t) pglob->gl_pathv[i]); + free((__ptr_t) pglob->gl_pathv); + } +} #endif /* CONFIG_GLOB */ #ifdef CONFIG_FAKE_GLOB @@ -443,15 +455,3 @@ glob_t *pglob; return 0; } #endif /* CONFIG_FAKE_GLOB */ - -/* Free storage allocated in PGLOB by a previous `glob' call. */ -void globfree(glob_t *pglob) -{ - if (pglob->gl_pathv != NULL) { - int i = pglob->gl_flags & GLOB_DOOFFS ? pglob->gl_offs : 0; - for (; i < pglob->gl_pathc; ++i) - if (pglob->gl_pathv[i] != NULL) - free((__ptr_t) pglob->gl_pathv[i]); - free((__ptr_t) pglob->gl_pathv); - } -} |