Commit 058b94fe by Tycho Andersen Committed by Stéphane Graber

don't truncate environment sometimes in setproctitle

Instead, let's just allocate new space for the proctitle to live and point the kernel at that. v2: take out testing hunk v3: check return from realloc Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent f8b2a49c
...@@ -1349,6 +1349,7 @@ char *get_template_path(const char *t) ...@@ -1349,6 +1349,7 @@ char *get_template_path(const char *t)
*/ */
int setproctitle(char *title) int setproctitle(char *title)
{ {
static char *proctitle = NULL;
char buf[2048], *tmp; char buf[2048], *tmp;
FILE *f; FILE *f;
int i, len, ret = 0; int i, len, ret = 0;
...@@ -1413,28 +1414,21 @@ int setproctitle(char *title) ...@@ -1413,28 +1414,21 @@ int setproctitle(char *title)
* want to have room for it. */ * want to have room for it. */
len = strlen(title) + 1; len = strlen(title) + 1;
/* We're truncating the environment, so we should use at most the /* If we don't have enough room by just overwriting the old proctitle,
* length of the argument + environment for the title. */ * let's allocate a new one.
if (len > env_end - arg_start) { */
arg_end = env_end; if (len > arg_end - arg_start) {
len = env_end - arg_start; void *m;
title[len-1] = '\0'; m = realloc(proctitle, len);
} else { if (!m)
/* Only truncate the environment if we're actually going to
* overwrite part of it. */
if (len >= arg_end - arg_start) {
env_start = env_end;
}
arg_end = arg_start + len;
/* check overflow */
if (arg_end < len || arg_end < arg_start) {
return -1; return -1;
} proctitle = m;
arg_start = (unsigned long) proctitle;
} }
arg_end = arg_start + len;
brk_val = syscall(__NR_brk, 0); brk_val = syscall(__NR_brk, 0);
prctl_map = (struct prctl_mm_map) { prctl_map = (struct prctl_mm_map) {
......
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