]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make sure that we call library init / free
authorAlan T. DeKok <aland@freeradius.org>
Sun, 4 Feb 2024 16:09:33 +0000 (11:09 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 4 Feb 2024 16:09:33 +0000 (11:09 -0500)
src/bin/fuzzer.c

index 6ca0a4bee2d84316eb7cf05a012d5e2cbe931a97..82f7b0ff1369cab864ab1ddc720a48a3e8d31d61 100644 (file)
@@ -42,6 +42,7 @@ static bool                   init = false;
 static fr_test_point_proto_decode_t *tp        = NULL;
 static dl_t                    *dl = NULL;
 static dl_loader_t             *dl_loader;
+static fr_dict_protocol_t      *dl_proto;
 
 static fr_dict_t               *dict = NULL;
 
@@ -50,6 +51,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
 
 static void exitHandler(void)
 {
+       if (dl_proto && dl_proto->free) dl_proto->free();
+
        fr_dict_free(&dict, __FILE__);
 
        if (dl && dl->handle) {
@@ -218,6 +221,14 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
                fr_exit_now(EXIT_FAILURE);
        }
 
+       snprintf(buffer, sizeof(buffer), "libfreeradius_%s_dict_protocol", proto);
+
+       dl_proto = dlsym(dl->handle, buffer);
+       if (dl_proto && dl_proto->init() && (dl_proto->init() < 0)) {
+               fr_perror("fuzzer: Failed initializing library %s", buffer);
+               fr_exit_now(EXIT_FAILURE);
+       }
+
        snprintf(buffer, sizeof(buffer), "%s_tp_decode_proto", proto);
 
        tp = dlsym(dl->handle, buffer);