From fd14fdb8272184155a965901e26170496b9de901 Mon Sep 17 00:00:00 2001 From: Liza Tretyakova Date: Sat, 19 May 2018 16:24:25 +0300 Subject: [PATCH] confile: add strdup failure check Signed-off-by: Liza Tretyakova [christian.brauner@ubuntu.com: coding style] Signed-off-by: Christian Brauner --- src/lxc/confile.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lxc/confile.c b/src/lxc/confile.c index cb595a340..091dc67d9 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -1689,8 +1689,8 @@ static int set_config_mount_auto(const char *key, const char *value, if (!strcmp(allowed_auto_mounts[i].token, token)) break; - if (strcmp("shmounts:", allowed_auto_mounts[i].token) == 0 - && strncmp("shmounts:", token, sizeof("shmounts:") - 1) == 0) { + if (strcmp("shmounts:", allowed_auto_mounts[i].token) == 0 && + strncmp("shmounts:", token, sizeof("shmounts:") - 1) == 0) { is_shmounts = true; break; } @@ -1705,11 +1705,21 @@ static int set_config_mount_auto(const char *key, const char *value, lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag; if (is_shmounts) { lxc_conf->shmount.path_host = strdup(token + (sizeof("shmounts:") - 1)); + if (!lxc_conf->shmount.path_host) { + SYSERROR("Failed to copy shmounts host path"); + break; + } + if (strcmp(lxc_conf->shmount.path_host, "") == 0) { ERROR("Invalid shmounts path: empty"); break; } + lxc_conf->shmount.path_cont = strdup("/dev/.lxc-mounts"); + if(!lxc_conf->shmount.path_cont) { + SYSERROR("Failed to copy shmounts container path"); + break; + } } } -- 2.47.2