From: Christian Brauner Date: Sat, 20 Jan 2018 20:26:33 +0000 (+0100) Subject: coverity: #1427668 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a48622d85140e329298f7ae2e45f7ce14449de0a;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 08ef03ee4..78fc27141 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -76,23 +76,25 @@ static void usage(void) { 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; }