Re: [PATCH master 1/3] glob: use empty globfree when compiling without CONFIG_GLOB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 19, 2021 at 07:26:06PM +0100, Ahmad Fatoum wrote:
> 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@xxxxxxxxx>
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---

Applied, thanks

Sascha

>  include/glob.h |  6 +++++-
>  lib/glob.c     | 24 ++++++++++++------------
>  2 files changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/include/glob.h b/include/glob.h
> index 5f532e6652c3..ec0ac66f8765 100644
> --- a/include/glob.h
> +++ b/include/glob.h
> @@ -177,6 +177,7 @@ extern int glob __P ((__const char *__restrict __pattern, int __flags,
>  		      int (*__errfunc) (__const char *, int),
>  		      glob_t *__restrict __pglob));
>  
> +extern void globfree __P ((glob_t *__pglob));
>  #else
>  static inline int glob __P ((__const char *__restrict __pattern, int __flags,
>  		      int (*__errfunc) (__const char *, int),
> @@ -184,9 +185,12 @@ static inline int glob __P ((__const char *__restrict __pattern, int __flags,
>  {
>  	return GLOB_ABORTED;
>  }
> +
> +static inline void globfree __P ((glob_t *__pglob))
> +{
> +}
>  #endif
>  /* Free storage allocated in PGLOB by a previous `glob' call.  */
> -extern void globfree __P ((glob_t *__pglob));
>  #else
>  extern int glob __P ((__const char *__restrict __pattern, int __flags,
>  		      int (*__errfunc) (__const char *, int),
> diff --git a/lib/glob.c b/lib/glob.c
> index 32f7afdce81b..8523bad9a7ef 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);
> -	}
> -}
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux