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().
This commit is contained in:
Ken Brown 2020-01-30 10:08:21 -05:00
parent 8ef32f2dcf
commit 76dca77f04

View File

@ -394,12 +394,13 @@ fhandler_base::fstat_fs (struct stat *buf)
return res; return res;
} }
/* Called by fstat_by_handle and fstat_by_name. */
int __reg2 int __reg2
fhandler_base::fstat_helper (struct stat *buf) fhandler_base::fstat_helper (struct stat *buf)
{ {
IO_STATUS_BLOCK st; IO_STATUS_BLOCK st;
FILE_COMPRESSION_INFORMATION fci; 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 (); PFILE_ALL_INFORMATION pfai = pc.fai ();
ULONG attributes = pc.file_attributes (); ULONG attributes = pc.file_attributes ();
@ -475,8 +476,8 @@ fhandler_base::fstat_helper (struct stat *buf)
else if (pc.issocket ()) else if (pc.issocket ())
buf->st_mode = S_IFSOCK; buf->st_mode = S_IFSOCK;
if (!get_file_attribute (is_fs_special () && !pc.issocket () ? NULL : h, pc, if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid,
&buf->st_mode, &buf->st_uid, &buf->st_gid)) &buf->st_gid))
{ {
/* If read-only attribute is set, modify ntsec return value */ /* If read-only attribute is set, modify ntsec return value */
if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY) if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY)