diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2023-10-30 19:40:31 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2023-10-31 10:52:02 +0100 |
commit | f0c90d3a8aa4409608abe76e035eab5919133a61 (patch) | |
tree | 641c1331ec6254b7003fbf82fac553d1a477b348 | |
parent | 386e762aa140a18c4bc3fd5963c4bbc6e2663c76 (diff) | |
download | newlib-f0c90d3a8aa4409608abe76e035eab5919133a61.zip newlib-f0c90d3a8aa4409608abe76e035eab5919133a61.tar.gz newlib-f0c90d3a8aa4409608abe76e035eab5919133a61.tar.bz2 |
Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twice
cwdstuff::set has a code snippet handling the case where a process
can't create a handle to a directory, e. g., due to permissions.
Commit 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD
prematurely on init") introduced a special case to handle this
situation at process initialization. It also introduces an early
mutex release, which is not required, but ok, because we're in the
init phase. Releasing the mutex twice is no problem since the mutexes
are recursive.
Fast forward to commit 0819679a7a210 ("Cygwin: cwd: use SRWLOCK
instead of muto"). The mechanical change from a recursive mutex
to a non-recursive SRWLOCK failed to notice that this very specific
situation will release the SRWLOCK twice.
Remove the superfluous release action. While at it, don't set dir to
NULL, but h, since dir will get the value of h anyway later on.
Setting h to NULL may not be necessary, but better safe than sorry.
Reported-by: tryandbuy >tryandbuy@proton.me>
Fixes: 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prematurely on init")
Fixes: 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r-- | winsup/cygwin/path.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/release/3.4.10 | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e788c7d..5ad9e20 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -4942,10 +4942,9 @@ cwdstuff::set (path_conv *nat_cwd, const char *posix_cwd) peb.ProcessParameters->CurrentDirectoryHandle, GetCurrentProcess (), &h, 0, TRUE, 0)) { - release_write (); if (peb.ProcessParameters->CurrentDirectoryHandle) debug_printf ("...and DuplicateHandle failed with %E."); - dir = NULL; + h = NULL; } } } diff --git a/winsup/cygwin/release/3.4.10 b/winsup/cygwin/release/3.4.10 index f34b131..c752839 100644 --- a/winsup/cygwin/release/3.4.10 +++ b/winsup/cygwin/release/3.4.10 @@ -3,3 +3,6 @@ Bug Fixes - Fix missing term in __cpuset_zero_s() prototoype in sys/cpuset.h. Addresses: https://cygwin.com/pipermail/cygwin/2023-September/254423.html + +- Fix hang in process initialization if cwd is unreadable. + Addresses: https://cygwin.com/pipermail/cygwin/2023-October/254604.html |