summaryrefslogtreecommitdiffstats
path: root/src/udev/fuzz-udev-rule-parse-value.c
blob: 1817c15b3b4e0d6228f0cf2d37efcf3b7a60f7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include <string.h>

#include "alloc-util.h"
#include "fuzz.h"
#include "udev-rules.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);

        fuzz_setup_logging();

        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;
}