[pacman-dev] [PATCH] BUG: Fix realloc of 0 bytes

tredaelli at archlinux.info tredaelli at archlinux.info
Fri Dec 19 10:11:18 UTC 2014


From: Timothy Redaelli <timothy.redaelli at gmail.com>

realloc with size == 0 can return NULL, and passing NULL to qsort will
cause a SEGFAULT (CERT MEM04-C)
---
 lib/libalpm/be_local.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 93763966..a734eba3 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -790,6 +790,9 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
 					memcpy(files[files_count].name, line, len);
 					files_count++;
 				}
+				if (files_count == 0) {
+					continue;
+				}
 				/* attempt to hand back any memory we don't need */
 				files = realloc(files, sizeof(alpm_file_t) * files_count);
 				/* make sure the list is sorted */
-- 
2.2.0


More information about the pacman-dev mailing list