From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 390873858034; Tue, 9 Feb 2021 15:36:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 390873858034 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] Revert "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: 3192da8f80ec50a6eb389ea6e147f93a50ccacd1 X-Git-Newrev: 89b3833211a850a165a3c844acb19a66524c3cc2 Message-Id: <20210209153641.390873858034@sourceware.org> Date: Tue, 9 Feb 2021 15:36:41 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Feb 2021 15:36:41 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=89b3833211a850a165a3c844acb19a66524c3cc2 commit 89b3833211a850a165a3c844acb19a66524c3cc2 Author: Ken Brown Date: Mon Feb 8 15:00:24 2021 -0500 Revert "Cygwin: fstat_helper: always use handle in call to get_file_attribute" This reverts commit 76dca77f049271e2529c25de8a396e65dbce615d. That commit was based on the incorrect assumption that get_stat_handle, when called on a FIFO in fstat_helper, would always return a handle that is safe to use for getting the file information. That assumption is true in many cases but not all. For example, if the call to fstat_helper arises from a call to fstat(2) on a FIFO that has been opened for writing, then get_stat_handle will return a pipe handle instead of a file handle. Diff: --- winsup/cygwin/fhandler_disk_file.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 5e58688b7..ef9171bbf 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -394,13 +394,12 @@ 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 (); /* Should always be pc.handle(). */ + HANDLE h = get_stat_handle (); PFILE_ALL_INFORMATION pfai = pc.fai (); ULONG attributes = pc.file_attributes (); @@ -476,8 +475,8 @@ fhandler_base::fstat_helper (struct stat *buf) else if (pc.issocket ()) buf->st_mode = S_IFSOCK; - if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid, - &buf->st_gid)) + if (!get_file_attribute (is_fs_special () && !pc.issocket () ? NULL : 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)