]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
check for NULL pointers before calling setenv()
authorRobert Schiele <rschiele@gmail.com>
Fri, 21 Aug 2015 05:35:34 +0000 (07:35 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 27 Aug 2015 21:26:08 +0000 (17:26 -0400)
Latest glibc release actually honours calling setenv with a NULL
pointer by causing SIGSEGV but checking pointers before submitting
to any system function is a good idea anyway.

Signed-off-by: Robert Schiele <rschiele@gmail.com>
src/lxc/lxccontainer.c
src/lxc/start.c

index 08d788a7a2466a1a27e46493eaf8f5dbbcb2b363..9a407c300934c304036274c207c488436a6aa53c 100644 (file)
@@ -2571,19 +2571,19 @@ static int clone_update_rootfs(struct clone_update_data *data)
 
        if (!lxc_list_empty(&conf->hooks[LXCHOOK_CLONE])) {
                /* Start of environment variable setup for hooks */
-               if (setenv("LXC_SRC_NAME", c0->name, 1)) {
+               if (c0->name && setenv("LXC_SRC_NAME", c0->name, 1)) {
                        SYSERROR("failed to set environment variable for source container name");
                }
-               if (setenv("LXC_NAME", c->name, 1)) {
+               if (c->name && setenv("LXC_NAME", c->name, 1)) {
                        SYSERROR("failed to set environment variable for container name");
                }
-               if (setenv("LXC_CONFIG_FILE", conf->rcfile, 1)) {
+               if (conf->rcfile && setenv("LXC_CONFIG_FILE", conf->rcfile, 1)) {
                        SYSERROR("failed to set environment variable for config path");
                }
-               if (setenv("LXC_ROOTFS_MOUNT", bdev->dest, 1)) {
+               if (bdev->dest && setenv("LXC_ROOTFS_MOUNT", bdev->dest, 1)) {
                        SYSERROR("failed to set environment variable for rootfs mount");
                }
-               if (setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1)) {
+               if (conf->rootfs.path && setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1)) {
                        SYSERROR("failed to set environment variable for rootfs mount");
                }
 
index 4d8479411337d60d2acb70e6e1a7a26c7d9b9272..64debc90c0c9657191a1a6a3e3a198c6bed1cb3a 100644 (file)
@@ -390,16 +390,16 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char
        }
 
        /* Start of environment variable setup for hooks */
-       if (setenv("LXC_NAME", name, 1)) {
+       if (name && setenv("LXC_NAME", name, 1)) {
                SYSERROR("failed to set environment variable for container name");
        }
-       if (setenv("LXC_CONFIG_FILE", conf->rcfile, 1)) {
+       if (conf->rcfile && setenv("LXC_CONFIG_FILE", conf->rcfile, 1)) {
                SYSERROR("failed to set environment variable for config path");
        }
-       if (setenv("LXC_ROOTFS_MOUNT", conf->rootfs.mount, 1)) {
+       if (conf->rootfs.mount && setenv("LXC_ROOTFS_MOUNT", conf->rootfs.mount, 1)) {
                SYSERROR("failed to set environment variable for rootfs mount");
        }
-       if (setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1)) {
+       if (conf->rootfs.path && setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1)) {
                SYSERROR("failed to set environment variable for rootfs mount");
        }
        if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) {