]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix integer overflow in setproctitle
authorTycho Andersen <tycho.andersen@canonical.com>
Mon, 13 Apr 2015 20:35:03 +0000 (14:35 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 13 Apr 2015 21:51:12 +0000 (16:51 -0500)
1. don't cast to long
2. check overflow before addition

v2: just remove the cast, don't change the type of the variables

Reported-by: Coverity
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/utils.c

index 1df6e8f57f9e4fbb9e3bfacf3d16586ed3af7f82..084b5563ef2bc2c18f1af615b520dca38d3d40d2 100644 (file)
@@ -1644,15 +1644,21 @@ int setproctitle(char *title)
                if (len >= arg_end - arg_start) {
                        env_start = env_end;
                }
+
+               /* check overflow */
+               if (arg_start + len < 0) {
+                       return -1;
+               }
+
                arg_end = arg_start + len;
        }
 
        strcpy((char*)arg_start, title);
 
-       ret |= prctl(PR_SET_MM, PR_SET_MM_ARG_START,   (long)arg_start, 0, 0);
-       ret |= prctl(PR_SET_MM, PR_SET_MM_ARG_END,     (long)arg_end, 0, 0);
-       ret |= prctl(PR_SET_MM, PR_SET_MM_ENV_START,   (long)env_start, 0, 0);
-       ret |= prctl(PR_SET_MM, PR_SET_MM_ENV_END,     (long)env_end, 0, 0);
+       ret |= prctl(PR_SET_MM, PR_SET_MM_ARG_START,   arg_start, 0, 0);
+       ret |= prctl(PR_SET_MM, PR_SET_MM_ARG_END,     arg_end, 0, 0);
+       ret |= prctl(PR_SET_MM, PR_SET_MM_ENV_START,   env_start, 0, 0);
+       ret |= prctl(PR_SET_MM, PR_SET_MM_ENV_END,     env_end, 0, 0);
 
        return ret;
 }