From: Tycho Andersen Date: Mon, 13 Apr 2015 20:35:03 +0000 (-0600) Subject: fix integer overflow in setproctitle X-Git-Tag: lxc-2.0.0.beta1~316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70642c33073faa6e44e34278633e5f00f4aaf618;p=thirdparty%2Flxc.git fix integer overflow in setproctitle 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 Acked-by: Stéphane Graber --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 1df6e8f57..084b5563e 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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; }