diff options
author | Michael Santos <michael.santos@gmail.com> | 2011-03-19 11:11:31 -0400 |
---|---|---|
committer | Daniel Lezcano <dlezcano@fr.ibm.com> | 2011-03-22 15:04:52 +0100 |
commit | bf83c5b90b347c4d61d5f0cff917c131c09edcd0 (patch) | |
tree | 5b69218017cb4167f3a841eb30921f828e55bb96 /src | |
parent | conf: increase buffer size to include spaces (diff) | |
download | lxc-bf83c5b90b347c4d61d5f0cff917c131c09edcd0.tar.gz lxc-bf83c5b90b347c4d61d5f0cff917c131c09edcd0.tar.bz2 lxc-bf83c5b90b347c4d61d5f0cff917c131c09edcd0.zip |
confile: check allocation succeeds
Signed-off-by: Michael Santos <michael.santos@gmail.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lxc/confile.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 1d30cba..791f04f 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -195,7 +195,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value, static int network_ifname(char **valuep, char *value) { - if (strlen(value) > IFNAMSIZ) { + if (strlen(value) >= IFNAMSIZ) { ERROR("invalid interface name: %s", value); return -1; } @@ -553,8 +553,8 @@ static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf { char *token = "lxc.cgroup."; char *subkey; - struct lxc_list *cglist; - struct lxc_cgroup *cgelem; + struct lxc_list *cglist = NULL; + struct lxc_cgroup *cgelem = NULL; subkey = strstr(key, token); @@ -571,21 +571,40 @@ static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf cglist = malloc(sizeof(*cglist)); if (!cglist) - return -1; + goto out; cgelem = malloc(sizeof(*cgelem)); - if (!cgelem) { - free(cglist); - return -1; - } + if (!cgelem) + goto out; + memset(cgelem, 0, sizeof(*cgelem)); cgelem->subsystem = strdup(subkey); cgelem->value = strdup(value); + + if (!cgelem->subsystem || !cgelem->value) + goto out; + cglist->elem = cgelem; lxc_list_add_tail(&lxc_conf->cgroup, cglist); return 0; + +out: + if (cglist) + free(cglist); + + if (cgelem) { + if (cgelem->subsystem) + free(cgelem->subsystem); + + if (cgelem->value) + free(cgelem->value); + + free(cgelem); + } + + return -1; } static int config_fstab(const char *key, char *value, struct lxc_conf *lxc_conf) @@ -631,6 +650,8 @@ static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf) return -1; mntelem = strdup(value); + if (!mntelem) + return -1; mntlist->elem = mntelem; lxc_list_add_tail(&lxc_conf->mount_list, mntlist); |