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