mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] fuzz: add test harness for fuzzing nul-terminated strings
@ 2025-08-21 20:59 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-08-21 20:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-22  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21 20:59 [PATCH 1/3] fuzz: add test harness for fuzzing nul-terminated strings Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox