]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-udev-rule-parse-value.c
f1d36669c45564db65e4c9b187a20103b327a407
[thirdparty/systemd.git] / src / fuzz / fuzz-udev-rule-parse-value.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <string.h>
4
5 #include "alloc-util.h"
6 #include "fuzz.h"
7 #include "udev-util.h"
8
9 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
10 _cleanup_free_ char *str = NULL;
11 int r;
12 char *value = UINT_TO_PTR(0x12345678U);
13 char *endpos = UINT_TO_PTR(0x87654321U);
14
15 assert_se(str = malloc(size + 1));
16 memcpy(str, data, size);
17 str[size] = '\0';
18
19 r = udev_rule_parse_value(str, &value, &endpos);
20
21 if (r < 0) {
22 /* not modified on failure */
23 assert_se(value == UINT_TO_PTR(0x12345678U));
24 assert_se(endpos == UINT_TO_PTR(0x87654321U));
25 } else {
26 assert_se(endpos <= str + size);
27 assert_se(endpos > str + 1);
28 }
29
30 return 0;
31 }