]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: Add fuzzer for efi conf/osrel parsing
authorJan Janssen <medhefgo@web.de>
Sun, 15 Oct 2023 09:43:59 +0000 (11:43 +0200)
committerJan Janssen <medhefgo@web.de>
Sun, 15 Oct 2023 15:41:25 +0000 (17:41 +0200)
src/boot/efi/fuzz-efi-osrel.c [new file with mode: 0644]
src/boot/efi/meson.build

diff --git a/src/boot/efi/fuzz-efi-osrel.c b/src/boot/efi/fuzz-efi-osrel.c
new file mode 100644 (file)
index 0000000..900e65b
--- /dev/null
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "alloc-util.h"
+#include "efi-string.h"
+#include "fuzz.h"
+
+#define SEP_LEN 4
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        if (outside_size_range(size, SEP_LEN + 1, 64 * 1024))
+                return 0;
+        if (data[SEP_LEN] != '\0')
+                return 0;
+
+        _cleanup_free_ char *p = memdup_suffix0(data + SEP_LEN + 1, size - SEP_LEN - 1);
+        assert_se(p);
+
+        size_t pos = 0;
+        char *key, *value;
+        while (line_get_key_value(p, (const char *) data, &pos, &key, &value)) {
+                assert_se(key);
+                assert_se(value);
+        }
+
+        return 0;
+}
index d5c10258044d4b070bb89eb947806c9f38032e12..c95132e4207cdf78843c9c762a2055ca6971ed2d 100644 (file)
@@ -41,6 +41,9 @@ executables += [
         efi_fuzz_template + {
                 'sources' : files('fuzz-efi-string.c'),
         },
+        efi_fuzz_template + {
+                'sources' : files('fuzz-efi-osrel.c'),
+        },
         efi_fuzz_template + {
                 'sources' : files('fuzz-efi-printf.c'),
         },