Commit 279428ea by Tycho Andersen Committed by Stéphane Graber

Process command line is null terminated

It turns out the process command line is in fact null terminated on the stack; this caused a bug where when the new process title was smaller than the old one, the first environment entry would be rendered as part of the process title. Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 8df26800
...@@ -1604,9 +1604,12 @@ int setproctitle(char *title) ...@@ -1604,9 +1604,12 @@ int setproctitle(char *title)
return -1; return -1;
} }
/* Include the null byte here, because in the calculations below we
* want to have room for it. */
len = strlen(title) + 1;
/* We're truncating the environment, so we should use at most the /* We're truncating the environment, so we should use at most the
* length of the argument + environment for the title. */ * length of the argument + environment for the title. */
len = strlen(title);
if (len > env_end - arg_start) { if (len > env_end - arg_start) {
arg_end = env_end; arg_end = env_end;
len = env_end - arg_start; len = env_end - arg_start;
...@@ -1619,9 +1622,7 @@ int setproctitle(char *title) ...@@ -1619,9 +1622,7 @@ int setproctitle(char *title)
arg_end = arg_start + len; arg_end = arg_start + len;
} }
strcpy((char*)arg_start, title);
/* memcpy instead of strcpy since this isn't null terminated */
memcpy((void*)arg_start, title, len);
ret |= prctl(PR_SET_MM, PR_SET_MM_ARG_START, (long)arg_start, 0, 0); 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_ARG_END, (long)arg_end, 0, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment