[PATCH 2/2] test: self: free a zero-sized buffer with free_sensitive()
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Sep 22 03:53:03 PDT 2026
free_sensitive() asks the allocator for the usable size of the buffer
before zeroing it, so it is one more path that has to cope with the
ZERO_SIZE_PTR that zero-sized allocations return. The sandbox got this
wrong until the previous commit and only ASAN noticed, so let's have the
allocator selftest walk over it.
Assisted-by: Claude:opus-5-1m
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
test/self/malloc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/test/self/malloc.c b/test/self/malloc.c
index 1ec351c3efe5..14d936f96a45 100644
--- a/test/self/malloc.c
+++ b/test/self/malloc.c
@@ -140,6 +140,11 @@ static void test_malloc(void)
__expect_cond(p == ZERO_SIZE_PTR, true, "get ZERO_SIZE_PTR for 0-size buffers", __func__, __LINE__);
free(p);
- free(tmp);
+
+ /*
+ * free_sensitive() asks the allocator for the usable size before it
+ * zeroes the buffer, so ZERO_SIZE_PTR has to survive that path too
+ */
+ free_sensitive(tmp);
}
bselftest(core, test_malloc);
--
2.47.3
More information about the barebox
mailing list