From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/3] sandbox: export list_fuzz_tests to sandbox_main
Date: Mon, 27 Oct 2025 08:42:31 +0100 [thread overview]
Message-ID: <20251027074236.2473380-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20251027074236.2473380-1-a.fatoum@barebox.org>
Using call_for_each_fuzz_test in the PBL is awkward, because the struct
definition isn't visible there and so we make use of the fact that a
string pointer is the first element of the struct.
Let's avoid this, by just providing a function that lists the fuzzers.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/sandbox/Makefile | 2 +-
arch/sandbox/os/common.c | 9 +++------
include/fuzz.h | 4 +++-
lib/fuzz.c | 13 +++++++++++++
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile
index 0318c8dd1452..fdff09c07cb9 100644
--- a/arch/sandbox/Makefile
+++ b/arch/sandbox/Makefile
@@ -96,7 +96,7 @@ SANDBOX_PROPER2PBL_GLUE_SYMS := \
strsep_unescaped start_barebox linux_get_stickypage_path \
stickypage mem_malloc_init \
barebox_register_filedev barebox_register_dtb barebox_register_console \
- barebox_errno barebox_loglevel call_for_each_fuzz_test setup_external_fuzz
+ barebox_errno barebox_loglevel list_fuzz_tests setup_external_fuzz
OBJCOPYFLAGS_barebox.o := $(addprefix --keep-global-symbol=, $(SANDBOX_PROPER2PBL_GLUE_SYMS))
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index e872a6381988..1628e28d83fb 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -56,14 +56,11 @@ extern int barebox_loglevel;
#endif
#ifdef CONFIG_FUZZ_EXTERNAL
-int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx);
+void list_fuzz_tests(int (*println)(const char *));
int setup_external_fuzz(const char *name,
int *argc, char ***argv);
#else
-static inline int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx)
-{
- return 0;
-}
+static inline void list_fuzz_tests(int (*println)(const char *)) { }
static inline int setup_external_fuzz(const char *name,
int *argc, char ***argv)
{
@@ -668,7 +665,7 @@ static int normal_main(int argc, char *argv[])
sdl_yres = strtoul(optarg, NULL, 0);
break;
case OPT_LIST_FUZZERS:
- call_for_each_fuzz_test(print_fuzz_test_name, NULL);
+ list_fuzz_tests(puts);
exit(0);
break;
case OPT_FUZZ:
diff --git a/include/fuzz.h b/include/fuzz.h
index f516d86ab769..11332e834753 100644
--- a/include/fuzz.h
+++ b/include/fuzz.h
@@ -20,7 +20,7 @@
* @func: Function to call to perform fuzz test on an input
*/
struct fuzz_test {
- const char *name; /* must be first member */
+ const char *name;
int (*func)(const uint8_t * data, size_t size);
};
@@ -86,6 +86,8 @@ static inline int fuzz_test_once(const struct fuzz_test *test, const u8 *data, s
int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *), void *ctx);
+void list_fuzz_tests(int (*println)(const char *));
+
int setup_external_fuzz(const char *fuzz_name,
int *argc, char ***argv);
diff --git a/lib/fuzz.c b/lib/fuzz.c
index 7be7ecedd922..038e176096bc 100644
--- a/lib/fuzz.c
+++ b/lib/fuzz.c
@@ -19,6 +19,19 @@ int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *ctx),
return 0;
}
+static int list_fuzz_test_one(const struct fuzz_test *test, void *ctx)
+{
+ int (*println)(const char *) = ctx;
+
+ println(test->name);
+ return 0;
+}
+
+void list_fuzz_tests(int (*println)(const char *))
+{
+ call_for_each_fuzz_test(list_fuzz_test_one, println);
+}
+
#ifdef CONFIG_FUZZ_EXTERNAL
const u8 *fuzzer_get_data(size_t *len);
#else
--
2.47.3
next prev parent reply other threads:[~2025-10-27 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 7:42 [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test Ahmad Fatoum
2025-10-27 7:42 ` Ahmad Fatoum [this message]
2025-10-27 7:42 ` [PATCH 3/3] fuzz: do not export for_each_fuzz_test Ahmad Fatoum
2025-10-28 7:26 ` [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test 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=20251027074236.2473380-2-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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