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