Commit 66b62e24 by Stéphane Graber

Merge pull request #638 from schiele/master

check for NULL pointers before calling setenv()
parents e54864d3 ab7efcf5
...@@ -2266,16 +2266,16 @@ static bool container_destroy(struct lxc_container *c) ...@@ -2266,16 +2266,16 @@ static bool container_destroy(struct lxc_container *c)
if (conf && !lxc_list_empty(&conf->hooks[LXCHOOK_DESTROY])) { if (conf && !lxc_list_empty(&conf->hooks[LXCHOOK_DESTROY])) {
/* Start of environment variable setup for hooks */ /* Start of environment variable setup for hooks */
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"); 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"); 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"); 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"); SYSERROR("failed to set environment variable for rootfs mount");
} }
if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) { if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) {
...@@ -2835,19 +2835,19 @@ static int clone_update_rootfs(struct clone_update_data *data) ...@@ -2835,19 +2835,19 @@ static int clone_update_rootfs(struct clone_update_data *data)
if (!lxc_list_empty(&conf->hooks[LXCHOOK_CLONE])) { if (!lxc_list_empty(&conf->hooks[LXCHOOK_CLONE])) {
/* Start of environment variable setup for hooks */ /* 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"); 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"); 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"); 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"); 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"); SYSERROR("failed to set environment variable for rootfs mount");
} }
......
...@@ -406,16 +406,16 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char ...@@ -406,16 +406,16 @@ struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf, const char
} }
/* Start of environment variable setup for hooks */ /* 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"); 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"); 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"); 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"); SYSERROR("failed to set environment variable for rootfs mount");
} }
if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) { if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment