From: Christian Brauner Date: Sat, 20 Jan 2018 20:26:33 +0000 (+0100) Subject: coverity: #1427668 X-Git-Tag: lxc-3.0.0.beta1~66^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d078b3c256816e4493398d1820f0e7d4df43a6f;p=thirdparty%2Flxc.git coverity: #1427668 Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 29394c80d..c44982726 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -197,23 +197,25 @@ static void kill_children(pid_t pid) static void remove_self(void) { - char path[PATH_MAX]; + int ret; ssize_t n; + char path[MAXPATHLEN] = {0}; n = readlink("/proc/self/exe", path, sizeof(path)); - if (n < 0) { + if (n < 0 || n >= MAXPATHLEN) { SYSERROR("Failed to readlink \"/proc/self/exe\""); return; } + path[n] = '\0'; - path[n] = 0; - - if (umount2(path, MNT_DETACH) < 0) { + ret = umount2(path, MNT_DETACH); + if (ret < 0) { SYSERROR("Failed to unmount \"%s\"", path); return; } - if (unlink(path) < 0) { + ret = unlink(path); + if (ret < 0) { SYSERROR("Failed to unlink \"%s\"", path); return; }