public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: fhandler_virtual::exists: always set fileid
Date: Tue,  9 Apr 2024 20:36:55 +0000 (GMT)	[thread overview]
Message-ID: <20240409203655.33E04385840D@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2855c35c41ed5c950e40ce0ae0d99d00185e05ad

commit 2855c35c41ed5c950e40ce0ae0d99d00185e05ad
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Apr 9 16:52:58 2024 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>

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;
 }

                 reply	other threads:[~2024-04-09 20:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240409203655.33E04385840D@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).