diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-01-31 23:53:31 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-02-01 22:18:15 +0100 |
commit | fa994f917d51997c6bc125161a473d1ed8d40229 (patch) | |
tree | 9b14975d98ca447a9bd4abb4fd96ff601fbec85b /src/activate/activate.c | |
parent | b72190e90f0846956e609075fb9113dba9bc8f0f (diff) |
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.
Diffstat (limited to 'src/activate/activate.c')
-rw-r--r-- | src/activate/activate.c | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c index 95083441ab..6709d9bb80 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -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) || |