public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: fstat_helper: always use handle in call to get_file_attribute
@ 2021-02-19 18:43 Ken Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Ken Brown @ 2021-02-19 18:43 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 70f63608699321fed8e3501469e5a8a3c416186d
Author: Ken Brown <kbrown@cornell.edu>
Date:   Wed Feb 10 21:15:20 2021 -0500

    Cygwin: fstat_helper: always use handle in call to get_file_attribute
    
    Previously, the call to get_file_attribute for FIFOs set the first
    argument to NULL instead of the handle h returned by get_stat_handle,
    thereby forcing the file to be opened for fetching the security
    descriptor in get_file_sd().  This was done because h might have been
    a pipe handle rather than a file handle, and its permissions would not
    necessarily reflect those of the file.
    
    That situation can no longer occur with the new fhandler_fifo::fstat
    introduced in the previous commit.

Diff:
---
 winsup/cygwin/fhandler_disk_file.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index ef9171bbf..6170427b0 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -475,8 +475,7 @@ fhandler_base::fstat_helper (struct stat *buf)
   else if (pc.issocket ())
     buf->st_mode = S_IFSOCK;
 
-  if (!get_file_attribute (is_fs_special () && !pc.issocket () ? NULL : h, pc,
-			   &buf->st_mode, &buf->st_uid, &buf->st_gid))
+  if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid, &buf->st_gid))
     {
       /* If read-only attribute is set, modify ntsec return value */
       if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [newlib-cygwin] Cygwin: fstat_helper: always use handle in call to get_file_attribute
@ 2020-01-31 12:45 Ken Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Ken Brown @ 2020-01-31 12:45 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 76dca77f049271e2529c25de8a396e65dbce615d
Author: Ken Brown <kbrown@cornell.edu>
Date:   Thu Jan 30 10:08:21 2020 -0500

    Cygwin: fstat_helper: always use handle in call to get_file_attribute
    
    When fhandler_base::fstat_helper is called, the handle h returned by
    get_stat_handle() should be pc.handle() and should be safe to use for
    getting the file information.  Previously, the call to
    get_file_attribute() for FIFOs set the first argument to NULL instead
    of h, thereby forcing the file to be opened for fetching the security
    descriptor in get_file_sd().

Diff:
---
 winsup/cygwin/fhandler_disk_file.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index f362e31..bc5967e 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -394,12 +394,13 @@ fhandler_base::fstat_fs (struct stat *buf)
   return res;
 }
 
+/* Called by fstat_by_handle and fstat_by_name. */
 int __reg2
 fhandler_base::fstat_helper (struct stat *buf)
 {
   IO_STATUS_BLOCK st;
   FILE_COMPRESSION_INFORMATION fci;
-  HANDLE h = get_stat_handle ();
+  HANDLE h = get_stat_handle ();      /* Should always be pc.handle(). */
   PFILE_ALL_INFORMATION pfai = pc.fai ();
   ULONG attributes = pc.file_attributes ();
 
@@ -475,8 +476,8 @@ fhandler_base::fstat_helper (struct stat *buf)
   else if (pc.issocket ())
     buf->st_mode = S_IFSOCK;
 
-  if (!get_file_attribute (is_fs_special () && !pc.issocket () ? NULL : h, pc,
-			   &buf->st_mode, &buf->st_uid, &buf->st_gid))
+  if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid,
+			   &buf->st_gid))
     {
       /* If read-only attribute is set, modify ntsec return value */
       if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-19 18:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 18:43 [newlib-cygwin] Cygwin: fstat_helper: always use handle in call to get_file_attribute Ken Brown
  -- strict thread matches above, loose matches on Subject: below --
2020-01-31 12:45 Ken Brown

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).