mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] test: self: free a zero-sized buffer with free_sensitive()
Date: Tue, 22 Sep 2026 12:53:03 +0200	[thread overview]
Message-ID: <20260922105308.386749-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260922105308.386749-1-a.fatoum@pengutronix.de>

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@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




  reply	other threads:[~2026-09-22 10:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 10:53 [PATCH 1/2] sandbox: route malloc_usable_size() through the PBL glue again Ahmad Fatoum
2026-09-22 10:53 ` Ahmad Fatoum [this message]
2026-09-23  6:09 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260922105308.386749-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox