"Fossies" - the Fresh Open Source Software Archive

Member "lxc-4.0.10/src/tests/fuzz-lxc-cgroup-init.c" (16 Jul 2021, 1025 Bytes) of package /linux/misc/lxc-4.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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