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

Allan McRae allan at archlinux.org
Mon Nov 17 14:51:40 UTC 2014


A corrupt local db filelist could result in a realloc of size zero.

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