]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
pull OSS-FUZZ patches in.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 18 Jan 2023 19:10:42 +0000 (14:10 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 18 Jan 2023 19:10:42 +0000 (14:10 -0500)
And rework them to follow our normal processes

src/bin/fuzzer.c
src/bin/fuzzer.mk

index c8368276ea2e879e1bde4ff6f4d5b77f5b0a66bb..314012831d5d159bef569f5d5a3255ff2ee41db0 100644 (file)
@@ -71,6 +71,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
        char const              *proto          = getenv("FR_LIBRARY_FUZZ_PROTOCOL");
        char const              *dict_dir       = getenv("FR_DICTIONARY_DIR");
        char const              *debug_lvl_str  = getenv("FR_DEBUG_LVL");
+       char const              *p;
+#ifdef LIB_FUZZING_ENGINE
+       char                    *dict_dir_to_free = NULL;
+       char                    *lib_dir_to_free = NULL;
+#endif
        char                    buffer[1024];
 
        if (!argc || !argv || !*argv) return -1; /* shut up clang scan */
@@ -122,7 +127,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
                int i, j;
 
                for (i = 0; i < *argc - 1; i++) {
-                       char *p = (*argv)[i];
+                       p = (*argv)[i];
 
                        if ((p[0] == '-') && (p[1] == 'D')) {
                                dict_dir = (*argv)[i + 1];
@@ -137,7 +142,28 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
                }
        }
 
+#ifdef LIB_FUZZING_ENGINE
+       /*
+        *      oss-fuzz puts the dictionaries, etc. into subdirectories named after the location of the
+        *      binary.  So we find the directory of the binary, and append "/dict" or "/lib" to find
+        *      dictionaries and libraries.
+        */
+       p = strrchr((*argv)[0], '/');
+       if (p) {
+               if (!dict_dir) {
+                       dict_dir = dict_dir_to_free = talloc_asprintf(NULL, "%.*s/dict", (int) (p - (*argv)[0]), (*argv)[0]);
+                       if (!dict_dir_to_free) fr_exit_now(EXIT_FAILURE);
+               }
+
+               if (!lib_dir) {
+                       lib_dir = lib_dir_to_free = talloc_asprintf(NULL, "%.*s/lib", (int) (p - (*argv)[0]), (*argv)[0]);
+                       if (!lib_dir_to_free) fr_exit_now(EXIT_FAILURE);
+               }
+       }
+#endif
+
        if (!dict_dir) dict_dir = DICTDIR;
+       if (!lib_dir) lib_dir = LIBDIR;
 
        /*
         *      When jobs=N is specified the fuzzer spawns worker processes via
@@ -195,6 +221,11 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
 
        init = true;
 
+#ifdef LIB_FUZZING_ENGINE
+       talloc_free(dict_dir_to_free);
+       talloc_free(lib_dir_to_free);
+#endif
+
        return 1;
 }
 
index 5f927cbc7b72a27b4dbaac00e4216c310d7cd31f..1edc5329d139959dc838de6ffa2120eba6b4e524 100644 (file)
@@ -28,6 +28,10 @@ TGT_LDLIBS           := $(LIBS)
 
 FUZZER_CORPUS_DIR      := src/tests/fuzzer-corpus
 
+ifdef LIB_FUZZING_ENGINE
+SRC_CFLAGS             += -DLIB_FUZZING_ENGINE
+endif
+
 #
 #  Ensure that the large data file is copied from git-lfs,
 #  and then the files are extracted.