[pacman-dev] [PATCH] Ensure filelist realloc uses positive size

Andrew Gregory andrew.gregory.8 at gmail.com
Mon Nov 17 16:20:16 UTC 2014


On 11/18/14 at 12:51am, Allan McRae wrote:
> A corrupt local db filelist could result in a realloc of size zero.

Maybe I'm missing something...  Calling realloc with size zero should free the
memory and return NULL, which seems like the right thing to do if there are no
files.

> Signed-off-by: Allan McRae <allan at archlinux.org>
> ---
>  lib/libalpm/be_local.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
> index 9376396..b8840d2 100644
> --- a/lib/libalpm/be_local.c
> +++ b/lib/libalpm/be_local.c
> @@ -791,7 +791,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
>  					files_count++;
>  				}
>  				/* attempt to hand back any memory we don't need */
> -				files = realloc(files, sizeof(alpm_file_t) * files_count);
> +				files = realloc(files, files_count ? sizeof(alpm_file_t) * files_count : 1);
>  				/* make sure the list is sorted */
>  				qsort(files, files_count, sizeof(alpm_file_t), _alpm_files_cmp);
>  				info->files.count = files_count;
> -- 
> 2.1.3


More information about the pacman-dev mailing list