]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/fuzz/fuzz-udev-rule-parse-value.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / fuzz / fuzz-udev-rule-parse-value.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
c32d562d
YLY
2
3#include <string.h>
4
5#include "alloc-util.h"
6#include "fuzz.h"
7#include "udev-util.h"
8
9int 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}