25RCSID(
"$Id: 3ca17f9601735631324c5429fbf6cd7bd7193a6e $")
27#include <freeradius-devel/util/dl.h>
28#include <freeradius-devel/util/conf.h>
29#include <freeradius-devel/util/dict.h>
30#include <freeradius-devel/util/atexit.h>
31#include <freeradius-devel/util/syserror.h>
32#include <freeradius-devel/util/strerror.h>
33#include <freeradius-devel/io/test_point.h>
80 our_dl_proto = dlsym(dl_handle,
buffer);
81 if (our_dl_proto && our_dl_proto->
init() && (our_dl_proto->
init() < 0)) {
91 char const *lib_dir = getenv(
"FR_LIBRARY_PATH");
92 char const *
proto = getenv(
"FR_LIBRARY_FUZZ_PROTOCOL");
93 char const *dict_dir = getenv(
"FR_DICTIONARY_DIR");
94 char const *debug_lvl_str = getenv(
"FR_DEBUG_LVL");
96#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
97 char *dict_dir_to_free = NULL;
98 char *lib_dir_to_free = NULL;
101 if (!argc || !argv || !*argv)
return -1;
137 proto = strrchr((*argv)[0],
'_');
149 for (i = 0; i < *argc - 1; i++) {
152 if ((p[0] ==
'-') && (p[1] ==
'D')) {
153 dict_dir = (*argv)[i + 1];
155 for (j = i + 2; j < *argc; i++, j++) {
156 (*argv)[i] = (*argv)[j];
165#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
171 p = strrchr((*argv)[0],
'/');
174 dict_dir = dict_dir_to_free = talloc_asprintf(NULL,
"%.*s/dict", (
int) (p - (*argv)[0]), (*argv)[0]);
179 lib_dir = lib_dir_to_free = talloc_asprintf(NULL,
"%.*s/lib", (
int) (p - (*argv)[0]), (*argv)[0]);
185 if (!dict_dir) dict_dir = DICTDIR;
186 if (!lib_dir) lib_dir = LIBDIR;
192 fr_perror(
"fuzzer: Failed setting library path");
201 if (setenv(
"FR_DICTIONARY_DIR", dict_dir, 1)) {
202 fprintf(stderr,
"Failed to set FR_DICTIONARY_DIR env variable\n");
212 fr_perror(
"fuzzer: Failed initializing internal dictionary");
217 fr_perror(
"Failed to find protocol for fuzzer");
236#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
248 void *decode_ctx = NULL;
255 fr_perror(
"fuzzer: Failed initializing test point decode_ctx");
259 tp->
func(ctx, &vps, buf, len, decode_ctx);
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.
static dl_loader_t * dl_loader
fr_test_point_proto_decode_t XX_PROTOCOL_XX_tp_decode_proto
static fr_dict_protocol_t * dl_proto
static fr_dict_protocol_t * fuzzer_dict_init(void *dl_handle, char const *proto)
int LLVMFuzzerInitialize(int *argc, char ***argv)
static void exitHandler(void)
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
void fr_talloc_fault_setup(void)
Register talloc fault handlers.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
fr_dict_protocol_free_t free
free the library
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.
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name, char const *dependent)
(Re-)Initialize the special internal 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.
Protocol-specific callbacks in libfreeradius-PROTOCOL.
int dl_search_global_path_set(char const *lib_dir)
Set the global library path.
void * handle
Handle returned by dlopen.
bool fr_hostname_lookups
hostname -> IP lookups?
bool fr_reverse_lookups
IP -> hostname lookups?
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
static char const * proto(int id, int porttype)
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.
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
fr_tp_proto_decode_t func
Decoder for proto layer.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Entry point for protocol decoders.
#define FR_DICTIONARY_INTERNAL_DIR
void fr_pair_list_debug(fr_pair_list_t const *list)
Dumps a list to the default logging destination - Useful for calling from debuggers.
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)