activate: fix memory allocation for execv() parameters

Make sure we construct the full environment block on the heap, so that we can clean things up properly if execv()
fails.
This commit is contained in:
Lennart Poettering 2016-01-31 23:53:31 +01:00
parent b72190e90f
commit fa994f917d

View file

@ -151,24 +151,44 @@ static int launch(char* name, char **argv, char **env, int fds) {
return log_oom();
STRV_FOREACH(s, arg_setenv) {
if (strchr(*s, '='))
envp[n_env++] = *s;
else {
if (strchr(*s, '=')) {
char *k;
k = strdup(*s);
if (!k)
return log_oom();
envp[n_env++] = k;
} else {
_cleanup_free_ char *p;
const char *n;
p = strappend(*s, "=");
if (!p)
return log_oom();
envp[n_env] = strv_find_prefix(env, p);
if (envp[n_env])
n_env ++;
n = strv_find_prefix(env, p);
if (!n)
continue;
envp[n_env] = strdup(n);
if (!envp[n_env])
return log_oom();
}
}
for (i = 0; i < ELEMENTSOF(tocopy); i++) {
envp[n_env] = strv_find_prefix(env, tocopy[i]);
if (envp[n_env])
n_env ++;
const char *n;
n = strv_find_prefix(env, tocopy[i]);
if (!n)
continue;
envp[n_env] = strdup(n);
if (!envp[n_env])
return log_oom();
n_env ++;
}
if ((asprintf((char**)(envp + n_env++), "LISTEN_FDS=%d", fds) < 0) ||