]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1427668
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Jan 2018 20:26:33 +0000 (21:26 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 7 Feb 2018 11:30:41 +0000 (12:30 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxc_init.c

index 08ef03ee4719e12df5b0b770976ff9d29e2e68ee..78fc271415e41766f990026c535e236540f6d488 100644 (file)
@@ -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;
        }