]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: local: Fixed use of unterminated string array of environment...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 9 May 2017 11:43:39 +0000 (13:43 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 23 May 2017 11:39:20 +0000 (13:39 +0200)
src/lib-program-client/program-client-local.c

index 913a88c5edb585948f6f87a4267d47651c358437..417e5278bbff076c42f71477fea07d4f273164ae 100644 (file)
@@ -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;
@@ -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 */
@@ -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");
@@ -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();