From 2855c35c41ed5c950e40ce0ae0d99d00185e05ad Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 9 Apr 2024 16:52:58 +0200 Subject: Cygwin: fhandler_virtual::exists: always set fileid Commit a0a25849f9dd ("Cygwin: fhandler_virtual: move fileid to path_conv member") broke `ls -l /proc/'. 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 --- 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 7629b54..baf0cae 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 20169d2..37bdff8 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 112aee8..631fe8c 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 b322c46..dac565c 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; } -- cgit v1.1