[PATCH 2/3] sandbox: export list_fuzz_tests to sandbox_main
Ahmad Fatoum
a.fatoum at barebox.org
Mon Oct 27 00:42:31 PDT 2025
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 at 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
More information about the barebox
mailing list