]>
Commit | Line | Data |
---|---|---|
74951960 CB |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | ||
e49c56d6 CB |
3 | #include "config.h" |
4 | ||
74951960 CB |
5 | #include <stddef.h> |
6 | #include <stdint.h> | |
7 | ||
8 | #include "cgroups/cgroup.h" | |
9 | #include "conf.h" | |
10 | #include "confile.h" | |
11 | #include "lxctest.h" | |
12 | #include "utils.h" | |
13 | ||
14 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | |
15 | int fd = -1; | |
16 | char tmpf[] = "/tmp/fuzz-lxc-cgroup-init-XXXXXX"; | |
17 | struct lxc_conf *conf = NULL; | |
18 | int ret; | |
19 | struct cgroup_ops *ops; | |
20 | ||
21 | /* | |
22 | * 100Kb should probably be enough to trigger all the issues | |
23 | * we're interested in without any timeouts | |
24 | */ | |
25 | if (size > 102400) | |
26 | return 0; | |
27 | ||
28 | fd = lxc_make_tmpfile(tmpf, false); | |
29 | lxc_test_assert_abort(fd >= 0); | |
30 | lxc_write_nointr(fd, data, size); | |
31 | close(fd); | |
32 | ||
33 | conf = lxc_conf_init(); | |
34 | lxc_test_assert_abort(conf); | |
35 | ||
36 | /* Test cgroup_init() with valid config. */ | |
37 | ops = cgroup_init(conf); | |
38 | cgroup_exit(ops); | |
39 | ||
40 | ret = lxc_config_read(tmpf, conf, false); | |
41 | if (ret == 0) { | |
42 | /* Test cgroup_init() with likely garbage config. */ | |
43 | ops = cgroup_init(conf); | |
44 | cgroup_exit(ops); | |
45 | } | |
46 | lxc_conf_free(conf); | |
47 | ||
48 | (void) unlink(tmpf); | |
49 | ||
50 | return 0; | |
51 | } | |
52 |