]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/fuzz-lxc-define-load.c
3f05b15c76e9e0ae61723a0cc9f88296f0f23c89
[mirror_lxc.git] / src / tests / fuzz-lxc-define-load.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 __do_free char *new_str = NULL;
13 struct lxc_container *c = NULL;
14 struct lxc_list defines;
15 struct lxc_list *it;
16 __do_close int devnull_fd = -EBADF;
17
18 if (size > 102400)
19 return 0;
20
21 c = lxc_container_new("FUZZ", NULL);
22 lxc_test_assert_abort(c);
23
24 new_str = (char *)malloc(size+1);
25 lxc_test_assert_abort(new_str);
26 memcpy(new_str, data, size);
27 new_str[size] = '\0';
28
29 lxc_list_init(&defines);
30
31 if (lxc_config_define_add(&defines, new_str) < 0)
32 goto out;
33
34 if (!lxc_config_define_load(&defines, c))
35 goto out;
36
37 devnull_fd = open_devnull();
38 lxc_test_assert_abort(devnull_fd >= 0);
39
40 lxc_list_for_each(it, &defines) {
41 __do_free char *val = NULL;
42 struct new_config_item *config_item = it->elem;
43 int len;
44
45 len = c->get_config_item(c, config_item->key, NULL, 0);
46 if (len < 0)
47 continue;
48
49 val = (char *)malloc(len + 1);
50 lxc_test_assert_abort(val);
51
52 if (c->get_config_item(c, config_item->key, val, len + 1) != len)
53 continue;
54
55 if (len > 0)
56 dprintf(devnull_fd, "[%s/%s]\n", config_item->key, val);
57 }
58
59 out:
60 lxc_container_put(c);
61 lxc_config_define_free(&defines);
62
63 return 0;
64 }