From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47911 invoked by alias); 31 Jan 2020 12:45:53 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 47869 invoked by uid 9996); 31 Jan 2020 12:45:53 -0000 Date: Fri, 31 Jan 2020 12:45:00 -0000 Message-ID: <20200131124553.47867.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fstat_helper: always use handle in call to get_file_attribute X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 8ef32f2dcfe48b540e64a4ec3ce0dcba5d3b70ce X-Git-Newrev: 76dca77f049271e2529c25de8a396e65dbce615d X-SW-Source: 2020-q1/txt/msg00050.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=76dca77f049271e2529c25de8a396e65dbce615d commit 76dca77f049271e2529c25de8a396e65dbce615d Author: Ken Brown 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)