25RCSID(
"$Id: 1a2ff164c2d266e7d0f416f9c6e4b78e935df196 $")
27#include <freeradius-devel/fuzzer/common.h>
57 char const *lib_dir = getenv(
"FR_LIBRARY_PATH");
58 char const *dict_dir = getenv(
"FR_DICTIONARY_DIR");
59 char const *debug_lvl_str = getenv(
"FR_DEBUG_LVL");
62 char const *proto = getenv(
"FR_LIBRARY_FUZZ_PROTOCOL");
63 char const *root_attr = getenv(
"FR_FUZZER_ROOT_ATTR");
67 if (!argc || !argv || !*argv)
return -1;
124 for (i = 0; i < *argc - 1; i++) {
127 if ((p[0] ==
'-') && (p[1] ==
'D')) {
128 dict_dir = (*argv)[i + 1];
130 for (j = i + 2; j < *argc; i++, j++) {
131 (*argv)[i] = (*argv)[j];
140#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
146 p = strrchr((*argv)[0],
'/');
150 if (!dict_dir)
return -1;
155 if (!lib_dir)
return -1;
160 if (!dict_dir) dict_dir = DICTDIR;
161 if (!lib_dir) lib_dir = LIBDIR;
167 fr_perror(
"fuzzer: Failed setting library path");
176 if (setenv(
"FR_DICTIONARY_DIR", dict_dir, 1)) {
177 fprintf(stderr,
"Failed to set FR_DICTIONARY_DIR env variable\n");
182 fr_perror(
"fuzzer: Failed initializing global dictionary context");
187 fr_perror(
"fuzzer: Failed initializing internal dictionary");
191 if (!load_proto)
return 0;
197 proto = strrchr((*argv)[0],
'_');
202 fr_perror(
"Failed to find protocol for fuzzer");
209 fr_perror(
"Failed to find root attribute '%s'", root_attr);
static int const char char buffer[256]
int fr_atexit_global_setup(void)
Setup the atexit handler, should be called at the start of a program's execution.
int fr_atexit_global_trigger_all(void)
Cause all global free triggers to fire.
fr_dict_protocol_t * dl_proto
int fuzzer_common_init(int *argc, char ***argv, bool load_proto)
Perform all bootstrapping for the fuzzer.
static void exitHandler(void)
fr_dict_attr_t const * root_da
static char panic_action[512]
The command to execute when panicking.
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
void fr_talloc_fault_setup(void)
Register talloc fault handlers.
fr_dict_protocol_free_t free
free the library
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char const *dependent))
(Re-)Initialize the special internal dictionary
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_protocol_init_t init
initialize the library
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
fr_dict_gctx_t * fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir))
Initialise the global protocol hashes.
Protocol-specific callbacks in libfreeradius-PROTOCOL.
int dl_search_global_path_set(char const *lib_dir)
Set the global library path.
bool fr_hostname_lookups
hostname -> IP lookups?
bool fr_reverse_lookups
IP -> hostname lookups?
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
int fr_time_start(void)
Initialize the local time.
#define FR_DICTIONARY_INTERNAL_DIR
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
#define fr_strerror_const(_msg)