]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/fuzz-lxc-define-load.c
tests: include config.h
[mirror_lxc.git] / src / tests / fuzz-lxc-define-load.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "config.h"
4
5 #include <stddef.h>
6 #include <stdint.h>
7
8 #include "conf.h"
9 #include "confile.h"
10 #include "lxctest.h"
11 #include "utils.h"
12
13 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
14 __do_free char *new_str = NULL;
15 struct lxc_container *c = NULL;
16 struct lxc_list defines;
17 struct lxc_list *it;
18 __do_close int devnull_fd = -EBADF;
19
20 if (size > 102400)
21 return 0;
22
23 c = lxc_container_new("FUZZ", NULL);
24 lxc_test_assert_abort(c);
25
26 new_str = (char *)malloc(size+1);
27 lxc_test_assert_abort(new_str);
28 memcpy(new_str, data, size);
29 new_str[size] = '\0';
30
31 lxc_list_init(&defines);
32
33 if (lxc_config_define_add(&defines, new_str) < 0)
34 goto out;
35
36 if (!lxc_config_define_load(&defines, c))
37 goto out;
38
39 devnull_fd = open_devnull();
40 lxc_test_assert_abort(devnull_fd >= 0);
41
42 lxc_list_for_each(it, &defines) {
43 __do_free char *val = NULL;
44 struct new_config_item *config_item = it->elem;
45 int len;
46
47 len = c->get_config_item(c, config_item->key, NULL, 0);
48 if (len < 0)
49 continue;
50
51 val = (char *)malloc(len + 1);
52 lxc_test_assert_abort(val);
53
54 if (c->get_config_item(c, config_item->key, val, len + 1) != len)
55 continue;
56
57 if (len > 0)
58 dprintf(devnull_fd, "[%s/%s]\n", config_item->key, val);
59 }
60
61 out:
62 lxc_container_put(c);
63 lxc_config_define_free(&defines);
64
65 return 0;
66 }