25RCSID(
"$Id: 8ef5ffc5a90c7f1047e259fc0f949cbe0fec6be0 $")
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/proto.h>
31#include <freeradius-devel/util/atexit.h>
32#include <freeradius-devel/util/syserror.h>
33#include <freeradius-devel/util/strerror.h>
34#include <freeradius-devel/io/test_point.h>
86 our_dl_proto = dlsym(dl_handle,
buffer);
87 if (our_dl_proto && our_dl_proto->
init() && (our_dl_proto->
init() < 0)) {
97 char const *lib_dir = getenv(
"FR_LIBRARY_PATH");
98 char const *proto = getenv(
"FR_LIBRARY_FUZZ_PROTOCOL");
99 char const *dict_dir = getenv(
"FR_DICTIONARY_DIR");
100 char const *debug_lvl_str = getenv(
"FR_DEBUG_LVL");
103#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
104 char *dict_dir_to_free = NULL;
105 char *lib_dir_to_free = NULL;
108 if (!argc || !argv || !*argv)
return -1;
128 fr_perror(
"fuzzer: Failed to register fault handler");
153 proto = strrchr((*argv)[0],
'_');
165 for (i = 0; i < *argc - 1; i++) {
168 if ((p[0] ==
'-') && (p[1] ==
'D')) {
169 dict_dir = (*argv)[i + 1];
171 for (j = i + 2; j < *argc; i++, j++) {
172 (*argv)[i] = (*argv)[j];
181#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
187 p = strrchr((*argv)[0],
'/');
190 dict_dir = dict_dir_to_free = talloc_asprintf(NULL,
"%.*s/dict", (
int) (p - (*argv)[0]), (*argv)[0]);
195 lib_dir = lib_dir_to_free = talloc_asprintf(NULL,
"%.*s/lib", (
int) (p - (*argv)[0]), (*argv)[0]);
201 if (!dict_dir) dict_dir = DICTDIR;
202 if (!lib_dir) lib_dir = LIBDIR;
208 fr_perror(
"fuzzer: Failed setting library path");
217 if (setenv(
"FR_DICTIONARY_DIR", dict_dir, 1)) {
218 fprintf(stderr,
"Failed to set FR_DICTIONARY_DIR env variable\n");
228 fr_perror(
"fuzzer: Failed initializing internal dictionary");
233 fr_perror(
"Failed to find protocol for fuzzer");
254 fr_perror(
"Failed initializing panic action");
261#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
275 void *decode_ctx = NULL;
284 fr_perror(
"fuzzer: Failed initializing test point decode_ctx");
289 fr_perror(
"fuzzer: Failed initializing test point encode_ctx");
306 if (tp_decode->
func(ctx, &vps, buf, len, decode_ctx) > 0) {
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
static TALLOC_CTX * autofree
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)
fr_test_point_proto_encode_t XX_PROTOCOL_XX_tp_encode_proto
static void exitHandler(void)
static uint8_t encoded_data[65536]
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
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.
#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 fr_internal_encode_ctx_t encode_ctx
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.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
fr_tp_proto_decode_t func
Decoder for proto layer.
fr_tp_proto_encode_t func
Encoder for proto layer.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Entry point for protocol decoders.
Entry point for protocol encoders.
int fr_time_start(void)
Initialize the local time.
#define FR_DICTIONARY_INTERNAL_DIR
void fr_pair_list_debug(FILE *fp, fr_pair_list_t const *list)
Dumps a list to the default logging destination - Useful for calling from debuggers.
#define PAIR_LIST_VERIFY_WITH_CTX(_c, _x)
#define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt,...)
#define FR_PROTO_TRACE(_fmt,...)
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)