Skip to content

Commit

Permalink
lib-program-client: local: Fixed use of unterminated string array of …
Browse files Browse the repository at this point in the history
…environment variables in exec_child().
  • Loading branch information
stephanbosch committed May 23, 2017
1 parent 61d198b commit b493240
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/lib-program-client/program-client-local.c
Expand Up @@ -45,7 +45,8 @@ static
void program_client_local_exited(struct program_client_local *plclient);

static
void exec_child(const char *bin_path, const char *const *args, const char *const *envs,
void exec_child(const char *bin_path, const char *const *args,
ARRAY_TYPE(const_string) *envs,
int in_fd, int out_fd, int *extra_fds, bool drop_stderr)
{
ARRAY_TYPE(const_string) exec_args;
Expand Down Expand Up @@ -111,9 +112,12 @@ void exec_child(const char *bin_path, const char *const *args, const char *const
/* Setup environment */

env_clean();
if (envs != NULL) {
for(; *envs != NULL; envs++)
env_put(*envs);
if (array_is_created(envs)) {
const char *const *env;

array_foreach(envs, env) {
env_put(*env);
}
}

/* Execute */
Expand Down Expand Up @@ -216,9 +220,6 @@ int program_client_local_connect(struct program_client *pclient)
}

if (plclient->pid == 0) {
unsigned int count;
const char *const *envs = NULL;

/* child */
if (fd_in[1] >= 0 && close(fd_in[1]) < 0)
i_error("close(pipe:in:wr) failed: %m");
Expand All @@ -239,10 +240,7 @@ int program_client_local_connect(struct program_client *pclient)
restrict_access(&pclient->set.restrict_set, pclient->set.home,
!pclient->set.allow_root);

if (array_is_created(&pclient->envs))
envs = array_get(&pclient->envs, &count);

exec_child(pclient->path, pclient->args, envs,
exec_child(pclient->path, pclient->args, &pclient->envs,
fd_in[0], fd_out[1], child_extra_fds,
pclient->set.drop_stderr);
i_unreached();
Expand Down

0 comments on commit b493240

Please sign in to comment.