[parted-devel] [PATCH 3/5] resize: Make sure hfsc_new_cachetable cannot overflow on 32bit

Brian C. Lane bcl at redhat.com
Mon Sep 14 19:10:02 BST 2026


Add a couple of PED_ASSERT checks on size to make sure the ped_malloc
call doesn't allocate less than expected.
---
 libparted/fs/r/hfs/cache.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libparted/fs/r/hfs/cache.c b/libparted/fs/r/hfs/cache.c
index bd3778e5..adaa7e79 100644
--- a/libparted/fs/r/hfs/cache.c
+++ b/libparted/fs/r/hfs/cache.c
@@ -49,6 +49,8 @@ hfsc_new_cachetable(unsigned int size)
 	ret->table_size = size;
 	ret->table_first_free = 0;
 
+        PED_ASSERT (size > 0);
+        PED_ASSERT ((size_t) size * sizeof(*ret->table) < SIZE_MAX);
 	ret->table = ped_malloc(sizeof(*ret->table)*size);
 	if (!ret->table) { free(ret); return NULL; }
 	memset(ret->table, 0, sizeof(*ret->table)*size);
-- 
2.55.0




More information about the parted-devel mailing list