https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2855c35c41ed5c950e40ce0ae0d99d00185e05ad
commit 2855c35c41ed5c950e40ce0ae0d99d00185e05ad Author: Corinna Vinschen <[email protected]> AuthorDate: Tue Apr 9 16:52:58 2024 +0200 Commit: Corinna Vinschen <[email protected]> CommitDate: Tue Apr 9 17:02:35 2024 +0200 Cygwin: fhandler_virtual::exists: always set fileid Commit a0a25849f9dd ("Cygwin: fhandler_virtual: move fileid to path_conv member") broke `ls -l /proc/<PID>'. Turns out, the commit forgot to set the fileid in case of a virtual root dir (i. e., returning virt_rootdir) in fhandlers utilizing fileid. This crashed opendir() due to a random fileid. Make sure to set fileid in any case. Fixes: a0a25849f9dd ("Cygwin: fhandler_virtual: move fileid to path_conv member") Signed-off-by: Corinna Vinschen <[email protected]> Diff: --- winsup/cygwin/fhandler/proc.cc | 6 +++++- winsup/cygwin/fhandler/process.cc | 6 +++++- winsup/cygwin/fhandler/procnet.cc | 6 +++++- winsup/cygwin/fhandler/procsysvipc.cc | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler/proc.cc b/winsup/cygwin/fhandler/proc.cc index 7629b54d29db..baf0cae1e8f9 100644 --- a/winsup/cygwin/fhandler/proc.cc +++ b/winsup/cygwin/fhandler/proc.cc @@ -180,7 +180,10 @@ fhandler_proc::exists () debug_printf ("exists (%s)", path); path += proc_len; if (*path == 0) - return virt_rootdir; + { + fileid () = 0; + return virt_rootdir; + } virt_tab_t *entry = virt_tab_search (path + 1, false, proc_tab, PROC_LINK_COUNT); if (entry) @@ -188,6 +191,7 @@ fhandler_proc::exists () fileid () = entry - proc_tab; return entry->type; } + fileid () = -1; return virt_none; } diff --git a/winsup/cygwin/fhandler/process.cc b/winsup/cygwin/fhandler/process.cc index 20169d22fe25..37bdff84e322 100644 --- a/winsup/cygwin/fhandler/process.cc +++ b/winsup/cygwin/fhandler/process.cc @@ -95,7 +95,10 @@ fhandler_process::exists () while (*path != 0 && !isdirsep (*path)) path++; if (*path == 0) - return virt_rootdir; + { + fileid () = 0; + return virt_rootdir; + } virt_tab_t *entry = virt_tab_search (path + 1, true, process_tab, PROCESS_LINK_COUNT); @@ -122,6 +125,7 @@ fhandler_process::exists () } } } + fileid () = -1; return virt_none; } diff --git a/winsup/cygwin/fhandler/procnet.cc b/winsup/cygwin/fhandler/procnet.cc index 112aee8a2dad..631fe8cc1e43 100644 --- a/winsup/cygwin/fhandler/procnet.cc +++ b/winsup/cygwin/fhandler/procnet.cc @@ -48,7 +48,10 @@ fhandler_procnet::exists () while (*path != 0 && !isdirsep (*path)) path++; if (*path == 0) - return virt_rootdir; + { + fileid () = 0; + return virt_rootdir; + } virt_tab_t *entry = virt_tab_search (path + 1, false, procnet_tab, PROCNET_LINK_COUNT); @@ -59,6 +62,7 @@ fhandler_procnet::exists () fileid () = entry - procnet_tab; return entry->type; } + fileid () = -1; return virt_none; } diff --git a/winsup/cygwin/fhandler/procsysvipc.cc b/winsup/cygwin/fhandler/procsysvipc.cc index b322c4601643..dac565c07092 100644 --- a/winsup/cygwin/fhandler/procsysvipc.cc +++ b/winsup/cygwin/fhandler/procsysvipc.cc @@ -61,7 +61,10 @@ fhandler_procsysvipc::exists () while (*path != 0 && !isdirsep (*path)) path++; if (*path == 0) - return virt_rootdir; + { + fileid () = 0; + return virt_rootdir; + } virt_tab_t *entry = virt_tab_search (path + 1, true, procsysvipc_tab, PROCSYSVIPC_LINK_COUNT); @@ -78,6 +81,7 @@ fhandler_procsysvipc::exists () fileid () = entry - procsysvipc_tab; return entry->type; } + fileid () = -1; return virt_none; }
