diff options
author | Ivan Zhakov <ivan@apache.org> | 2023-01-21 13:54:24 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2023-01-21 13:54:24 +0000 |
commit | 5ccfca2c9d9d386d22c7b61a798fcdb4b77c6acc (patch) | |
tree | aa1989518790389249e5c570fa5fe830196f7cf3 | |
parent | c8adeaba01de353b20b7e1212c7ee0153b44979a (diff) | |
download | apr-5ccfca2c9d9d386d22c7b61a798fcdb4b77c6acc.tar.gz |
apr_proc_create(): Fix incorrect error handling when pipes are redirected
on Windows.
* threadproc/win32/proc.c
(apr_proc_create): Save last error immediately after CreateProcessAsUserW()/
CreateProcessW() call, otherwise it can be lost by later calls.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1906863 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | threadproc/win32/proc.c | 25 |
2 files changed, 22 insertions, 6 deletions
@@ -268,6 +268,9 @@ Changes for APR 2.0.0 *) apr_thread_create: Fix potential race condition on Windows. [Ivan Zhakov] + *) apr_proc_create(): Fix incorrect error handling when pipes are redirected + 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 38e09ad6f..0458c1db3 100644 --- a/threadproc/win32/proc.c +++ b/threadproc/win32/proc.c @@ -865,7 +865,7 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, LeaveCriticalSection(&proc_lock); return rv; } - rv = CreateProcessAsUserW(attr->user_token, + if (!CreateProcessAsUserW(attr->user_token, wprg, wcmd, attr->sa, NULL, @@ -873,18 +873,30 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, dwCreationFlags, pEnvBlock, wcwd, - &si, &pi); + &si, &pi)) { + /* Save error code. */ + rv = apr_get_os_error(); + } + else { + rv = APR_SUCCESS; + } RevertToSelf(); } else { - rv = CreateProcessW(wprg, wcmd, /* Executable & Command line */ + if (!CreateProcessW(wprg, wcmd, /* Executable & Command line */ NULL, NULL, /* Proc & thread security attributes */ TRUE, /* Inherit handles */ dwCreationFlags, /* Creation flags */ pEnvBlock, /* Environment block */ wcwd, /* Current directory name */ - &si, &pi); + &si, &pi)) { + /* Save error code. */ + rv = apr_get_os_error(); + } + else { + rv = APR_SUCCESS; + } } if ((attr->child_in && attr->child_in->filehand) @@ -912,8 +924,9 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, /* Check CreateProcess result */ - if (!rv) - return apr_get_os_error(); + if (rv) { + return rv; + } /* XXX Orphaned handle warning - no fix due to broken apr_proc_t api. */ |