]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
log: handle empty log name
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 26 Mar 2021 11:10:02 +0000 (12:10 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 29 Mar 2021 15:00:36 +0000 (17:00 +0200)
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32491
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/log.c
src/tests/parse_config_file.c

index 146b8ec85ba92aa9ab1ce2d5bfc19e0f7c0b8dbb..aa643c104bd11a0dc0ef17ac76dd60c6a147eb0d 100644 (file)
@@ -1461,6 +1461,9 @@ static int set_config_log_file(const char *key, const char *value,
                return 0;
        }
 
+       if (!abspath(value))
+               return ret_errno(EINVAL);
+
        /*
         * Store these values in the lxc_conf, and then try to set for actual
         * current logging.
index 90a56e26a1b718f943e4c35f0b8803f8bd0910b7..4733fcdeb12afa1fcc6666b51dc831c5d51a6ca7 100644 (file)
@@ -489,6 +489,12 @@ static int build_dir(const char *name)
        __do_free char *n = NULL;
        char *e, *p;
 
+       if (is_empty_string(name))
+               return ret_errno(EINVAL);
+
+       if (!abspath(name))
+               return ret_errno(EINVAL);
+
        /* Make copy of the string since we'll be modifying it. */
        n = strdup(name);
        if (!n)
@@ -604,7 +610,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs)
        if (lxc_log_fd >= 0)
                lxc_log_close();
 
-       if (!fname)
+       if (is_empty_string(fname))
                return ret_errno(EINVAL);
 
        if (strlen(fname) == 0) {
@@ -820,6 +826,9 @@ int lxc_log_set_file(int *fd, const char *fname)
        if (*fd >= 0)
                close_prot_errno_disarm(*fd);
 
+       if (is_empty_string(fname))
+               return ret_errno(EINVAL);
+
        if (build_dir(fname))
                return -errno;
 
index 9adbdd6a6761d0c0c9ae02f24d5cf9be4f2eaf41..237f2f3cc49bad3147d265035212e42e642b421d 100644 (file)
@@ -884,6 +884,11 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+       if (c->set_config_item(c, "lxc.log.file=", "./")) {
+               lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.log.file\" to \"./\"");
+               return -1;
+       }
+
        fret = EXIT_SUCCESS;
 
 non_test_error: