]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: add fuzzer for udev_rule_parse_value
authorYu, Li-Yu <afg984@gmail.com>
Sat, 24 Oct 2020 18:01:29 +0000 (02:01 +0800)
committerYu, Li-Yu <afg984@gmail.com>
Thu, 29 Oct 2020 12:19:29 +0000 (20:19 +0800)
src/fuzz/fuzz-udev-rule-parse-value.c [new file with mode: 0644]
src/fuzz/meson.build

diff --git a/src/fuzz/fuzz-udev-rule-parse-value.c b/src/fuzz/fuzz-udev-rule-parse-value.c
new file mode 100644 (file)
index 0000000..f1d3666
--- /dev/null
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include <string.h>
+
+#include "alloc-util.h"
+#include "fuzz.h"
+#include "udev-util.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        _cleanup_free_ char *str = NULL;
+        int r;
+        char *value = UINT_TO_PTR(0x12345678U);
+        char *endpos = UINT_TO_PTR(0x87654321U);
+
+        assert_se(str = malloc(size + 1));
+        memcpy(str, data, size);
+        str[size] = '\0';
+
+        r = udev_rule_parse_value(str, &value, &endpos);
+
+        if (r < 0) {
+                /* not modified on failure */
+                assert_se(value == UINT_TO_PTR(0x12345678U));
+                assert_se(endpos == UINT_TO_PTR(0x87654321U));
+        } else {
+                assert_se(endpos <= str + size);
+                assert_se(endpos > str + 1);
+        }
+
+        return 0;
+}
index 01f119fcd0b374586ba98979b3a87aec77065c77..9b5491940db6530286c6ada13c614ea8468bff58 100644 (file)
@@ -152,4 +152,8 @@ fuzzers += [
           'src/xdg-autostart-generator/xdg-autostart-service.c'],
          [],
          []],
+
+        [['src/fuzz/fuzz-udev-rule-parse-value.c'],
+         [libshared],
+         []],
 ]