summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan@13f79535-47bb-0310-9956-ffa450edef68>2023-01-21 15:52:22 +0000
committerivan <ivan@13f79535-47bb-0310-9956-ffa450edef68>2023-01-21 15:52:22 +0000
commit1c9e2c8793c62883f9400cf9a429daa472b0fe5c (patch)
tree07157cbab2eb839a9ec3457a4b4ed9e51b69973c
parentae93ca1f42e6f47bd5134e4dcc61a61062952ada (diff)
downloadlibapr-1c9e2c8793c62883f9400cf9a429daa472b0fe5c.tar.gz
Fix potential handle leak when apr_proc_create() is used from from multiple
threads on Windows. * threadproc/win32/proc.c (apr_proc_create): Close our side of pipes before releasing lock: otherwise they could like to other process when apr_proc_create() is used from from multiple threads. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1906885 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES3
-rw-r--r--threadproc/win32/proc.c24
2 files changed, 18 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index bbcd3b594..21fe5c497 100644
--- a/CHANGES
+++ b/CHANGES
@@ -271,6 +271,9 @@ Changes for APR 2.0.0
*) apr_proc_create(): Fix incorrect error handling when pipes are redirected
on Windows [Ivan Zhakov]
+ *) apr_proc_create(): Fix potential handle leak when apr_proc_create() is used
+ from from multiple threads on Windows [Ivan Zhakov]
+
Changes for APR and APR-util 1.7.x and later:
*) http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/CHANGES?view=markup
diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c
index 0458c1db3..af9d56d8a 100644
--- a/threadproc/win32/proc.c
+++ b/threadproc/win32/proc.c
@@ -915,6 +915,21 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
SetHandleInformation(GetStdHandle(STD_ERROR_HANDLE),
stderr_reset, stderr_reset);
}
+
+ /* Close our side of pipes before releasing lock: otherwise they
+ * could like to other process when apr_proc_create() is used from
+ * from multiple threads.
+ */
+ if ((attr->child_in) && (attr->child_in != &no_file)) {
+ apr_file_close(attr->child_in);
+ }
+ if ((attr->child_out) && (attr->child_out != &no_file)) {
+ apr_file_close(attr->child_out);
+ }
+ if ((attr->child_err) && (attr->child_err != &no_file)) {
+ apr_file_close(attr->child_err);
+ }
+
/* RELEASE CRITICAL SECTION
* The state of the inherited handles has been restored.
*/
@@ -933,15 +948,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
new->hproc = pi.hProcess;
new->pid = pi.dwProcessId;
- if ((attr->child_in) && (attr->child_in != &no_file)) {
- apr_file_close(attr->child_in);
- }
- if ((attr->child_out) && (attr->child_out != &no_file)) {
- apr_file_close(attr->child_out);
- }
- if ((attr->child_err) && (attr->child_err != &no_file)) {
- apr_file_close(attr->child_err);
- }
CloseHandle(pi.hThread);
return APR_SUCCESS;