]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allocate and free decode_ctx on every run
authorAlan T. DeKok <aland@freeradius.org>
Mon, 25 Oct 2021 17:09:21 +0000 (13:09 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 25 Oct 2021 17:12:41 +0000 (13:12 -0400)
src/bin/fuzzer.c

index b5d294ef48d398fbe52c6dce820b7a621985c1f4..5b4d23072125ced296a02a033882487be8d27ae7 100644 (file)
@@ -39,7 +39,6 @@ RCSID("$Id$")
  */
 
 static bool                    init = false;
-static void                    *decode_ctx = NULL;
 static fr_test_point_proto_decode_t *tp        = NULL;
 static dl_t                    *dl = NULL;
 static dl_loader_t             *dl_loader;
@@ -177,11 +176,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
                fr_exit_now(EXIT_FAILURE);
        }
 
-       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, NULL) < 0)) {
-               fr_perror("fuzzer: Failed initializing test point %s", buffer);
-               fr_exit_now(EXIT_FAILURE);
-       }
-
        init = true;
 
        return 1;
@@ -191,11 +185,18 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
 {
        TALLOC_CTX *   ctx = talloc_init_const("fuzzer");
        fr_pair_list_t vps;
+       void *decode_ctx = NULL;
 
        fr_pair_list_init(&vps);
        if (!init) LLVMFuzzerInitialize(NULL, NULL);
 
+       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, NULL) < 0)) {
+               fr_perror("fuzzer: Failed initializing test point decode_ctx");
+               fr_exit_now(EXIT_FAILURE);
+       }
+
        tp->func(ctx, &vps, buf, len, decode_ctx);
+       talloc_free(decode_ctx);
        talloc_free(ctx);
 
        /*