From: Alan T. DeKok Date: Mon, 25 May 2026 11:57:42 +0000 (-0400) Subject: make xlat fuzzer use the common framework X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ba545de699d67e40ac699c38359bbda5ff549a7;p=thirdparty%2Ffreeradius-server.git make xlat fuzzer use the common framework and update it so that it actually runs --- diff --git a/src/fuzzer/all.mk b/src/fuzzer/all.mk index 008cf169900..3a1981a9297 100644 --- a/src/fuzzer/all.mk +++ b/src/fuzzer/all.mk @@ -25,6 +25,7 @@ FUZZER_NON_PROTOCOL_TARGETS = util json value xlat # json / cf / value / xlat are standalone parsers that don't. # FUZZER_util_ARGS := -D share/dictionary +FUZZER_xlat_ARGS := -D share/dictionary # # Add the fuzzer only if everything was built with the fuzzing flags. diff --git a/src/fuzzer/fuzzer_xlat.c b/src/fuzzer/fuzzer_xlat.c index e457dd1e061..a4d9acc4b7c 100644 --- a/src/fuzzer/fuzzer_xlat.c +++ b/src/fuzzer/fuzzer_xlat.c @@ -35,17 +35,7 @@ */ RCSID("$Id$") -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include @@ -55,59 +45,18 @@ RCSID("$Id$") int LLVMFuzzerInitialize(int *argc, char ***argv); int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len); -static bool init_done = false; -static fr_dict_t *dict_internal = NULL; - int LLVMFuzzerInitialize(int *argc, char ***argv) { - char const *dict_dir = NULL; - char const *lib_dir = NULL; - char *dict_buf = NULL, *lib_buf = NULL; - char const *p; - - if (init_done) return 0; - if (!argc || !argv || !*argv) return -1; + if (dict) return 0; - fr_atexit_global_setup(); - fr_talloc_fault_setup(); - fr_strerror_const("fuzz"); - fr_strerror_clear(); + if (fuzzer_common_init(argc, argv, false) < 0) fr_exit_now(EXIT_FAILURE); if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) { error: - talloc_free(dict_buf); - talloc_free(lib_buf); fr_perror("fuzzer_xlat"); - return -1; - } - - dict_dir = getenv("FR_DICTIONARY_DIR"); - lib_dir = getenv("FR_LIBRARY_PATH"); - - p = strrchr((*argv)[0], '/'); - if (p) { - if (!dict_dir) { - dict_buf = talloc_asprintf(NULL, "%.*s/dict", - (int)(p - (*argv)[0]), (*argv)[0]); - if (!dict_buf) goto error; - dict_dir = dict_buf; - } - if (!lib_dir) { - lib_buf = talloc_asprintf(NULL, "%.*s/lib", - (int)(p - (*argv)[0]), (*argv)[0]); - if (!lib_buf) goto error; - lib_dir = lib_buf; - } + fr_exit_now(EXIT_FAILURE); } - if (lib_dir && dl_search_global_path_set(lib_dir) < 0) goto error; - - if (dict_dir) (void) setenv("FR_DICTIONARY_DIR", dict_dir, 1); - - if (!fr_dict_global_ctx_init(NULL, true, dict_dir ? dict_dir : "share/dictionary")) goto error; - - if (fr_dict_internal_afrom_file(&dict_internal, FR_DICTIONARY_INTERNAL_DIR, __FILE__) < 0) goto error; - if (request_global_init() < 0) goto error; /* @@ -116,10 +65,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) */ if (unlang_global_init() < 0) goto error; - talloc_free(dict_buf); - talloc_free(lib_buf); - - init_done = true; return 0; } @@ -146,7 +91,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) size_t fmt_len; fr_slen_t slen; - if (!init_done) return 0; + if (!dict) return 0; if (size < 2) return 0; if (size > 4096) return 0; /* keep iterations fast */ @@ -178,7 +123,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) */ t_rules = (tmpl_rules_t) { .attr = (tmpl_attr_rules_t) { - .dict_def = dict_internal, + .dict_def = dict, .list_def = request_attr_request, .allow_unresolved = false, .allow_unknown = false, @@ -219,7 +164,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) */ { xlat_res_rules_t const xr_rules = { - .tr_rules = &(tmpl_res_rules_t){ .dict_def = dict_internal }, + .tr_rules = &(tmpl_res_rules_t){ .dict_def = dict }, .allow_unresolved = false, }; (void) xlat_resolve(head, &xr_rules); diff --git a/src/fuzzer/fuzzer_xlat.mk b/src/fuzzer/fuzzer_xlat.mk index c44bc0b874c..9aeb8cf1338 100644 --- a/src/fuzzer/fuzzer_xlat.mk +++ b/src/fuzzer/fuzzer_xlat.mk @@ -1,5 +1,5 @@ TARGET := fuzzer_xlat$(E) -SOURCES := fuzzer_xlat.c +SOURCES := fuzzer_xlat.c common.c TGT_PREREQS := $(LIBFREERADIUS_SERVER)