[PATCH v1 2/2] test: env: add test for himport_r SIZE_MAX overflow guard
Aristo Chen
aristo.chen at canonical.com
Wed Apr 8 16:03:36 CEST 2026
Add a unit test that verifies himport_r rejects SIZE_MAX as the size
argument, ensuring the integer overflow guard added to lib/hashtable.c
is exercised and not accidentally regressed.
Signed-off-by: Aristo Chen <aristo.chen at canonical.com>
---
test/env/hashtable.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/test/env/hashtable.c b/test/env/hashtable.c
index 16e49358888..ce9689f46d7 100644
--- a/test/env/hashtable.c
+++ b/test/env/hashtable.c
@@ -122,3 +122,20 @@ static int env_test_htab_deletes(struct unit_test_state *uts)
return 0;
}
ENV_TEST(env_test_htab_deletes, 0);
+
+/* Verify himport_r rejects SIZE_MAX to prevent integer overflow in malloc */
+static int env_test_htab_import_overflow(struct unit_test_state *uts)
+{
+ struct hsearch_data htab;
+
+ memset(&htab, 0, sizeof(htab));
+ ut_asserteq(1, hcreate_r(SIZE, &htab));
+
+ /* SIZE_MAX would cause malloc(size + 1) to wrap to malloc(0) */
+ ut_asserteq(0, himport_r(&htab, "", SIZE_MAX, '\0', 0, 0, 0, NULL));
+
+ hdestroy_r(&htab);
+ return 0;
+}
+
+ENV_TEST(env_test_htab_import_overflow, 0);
--
2.43.0
More information about the U-Boot
mailing list