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 1/3] fuzz: add test harness for fuzzing nul-terminated strings
Date: Thu, 21 Aug 2025 22:59:40 +0200	[thread overview]
Message-ID: <20250821205942.1435683-1-a.fatoum@pengutronix.de> (raw)

Many APIs expect NUL terminated strings, for example the JSON Web Token
decoding functions.

Add a helper to make it easy to fuzz such functions. As we are
allocating anew anyway, we pass along the buffer mutably as well as the
original size, so the harness is useful for a wider range of API.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/fuzz.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/fuzz.h b/include/fuzz.h
index bd95ae6203b0..caebc284d5db 100644
--- a/include/fuzz.h
+++ b/include/fuzz.h
@@ -9,6 +9,8 @@
 
 #include <linux/types.h>
 #include <linux/compiler_types.h>
+#include <linux/bug.h>
+#include <linux/string.h>
 #include <ramdisk.h>
 
 /**
@@ -65,6 +67,18 @@ extern const struct fuzz_test __barebox_fuzz_tests_end;
 	}							\
 	fuzz_test(_name, _func##_ramdisk)
 
+#define fuzz_test_str(_name, _func)				\
+	static int _func##_str(const u8 *_data, size_t size)	\
+	{							\
+		int ret;					\
+		char *data = memdup_nul(_data, size);		\
+		BUG_ON(!data);					\
+		ret = _func(data, size);			\
+		free(data);					\
+		return ret;					\
+	}							\
+	fuzz_test(_name, _func##_str)
+
 static inline int fuzz_test_once(const struct fuzz_test *test, const u8 *data, size_t len)
 {
 	return test->func(data, len);
-- 
2.39.5




             reply	other threads:[~2025-08-22  2:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 20:59 Ahmad Fatoum [this message]
2025-08-21 20:59 ` [PATCH 2/3] test: self: jwt: add dedicated option for development_rsa2048.pem Ahmad Fatoum
2025-08-21 20:59 ` [PATCH 3/3] security: jwt: add simple fuzzer Ahmad Fatoum

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=20250821205942.1435683-1-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