From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79718 invoked by alias); 5 Feb 2019 14:37:06 -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 79674 invoked by uid 9078); 5 Feb 2019 14:37:06 -0000 Date: Tue, 05 Feb 2019 14:37:00 -0000 Message-ID: <20190205143706.79671.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: proc fd: pass along open mode when reopening file X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 7225a82c1a4e90bcea2a17da12a427d1e783de30 X-Git-Newrev: 1f6340aa8bd8cde79b45f66b4766bfb70b490a9b X-SW-Source: 2019-q1/txt/msg00132.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1f6340aa8bd8cde79b45f66b4766bfb70b490a9b commit 1f6340aa8bd8cde79b45f66b4766bfb70b490a9b Author: Corinna Vinschen Date: Tue Feb 5 15:20:13 2019 +0100 Cygwin: proc fd: pass along open mode when reopening file The reopen code neglected to pass along the requested open mode correctly. This may end up reopening the file with incorrect access mask, or duplicating the wrong pipe handle. Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler.cc | 2 +- winsup/cygwin/fhandler.h | 4 ++-- winsup/cygwin/fhandler_process_fd.cc | 4 ++-- winsup/cygwin/syscalls.cc | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 07a0482..659435e 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -792,7 +792,7 @@ done: } fhandler_base * -fhandler_base::fd_reopen (int) +fhandler_base::fd_reopen (int, mode_t) { /* This is implemented in fhandler_process only. */ return NULL; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 97804ed..079385d 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -331,7 +331,7 @@ class fhandler_base int open_with_arch (int, mode_t = 0); int open_null (int flags); virtual int open (int, mode_t); - virtual fhandler_base *fd_reopen (int); + virtual fhandler_base *fd_reopen (int, mode_t); virtual void open_setup (int flags); void set_unique_id (int64_t u) { unique_id = u; } void set_unique_id () { NtAllocateLocallyUniqueId ((PLUID) &unique_id); } @@ -2587,7 +2587,7 @@ class fhandler_process_fd : public fhandler_process fhandler_process_fd () : fhandler_process () {} fhandler_process_fd (void *) {} - virtual fhandler_base *fd_reopen (int); + virtual fhandler_base *fd_reopen (int, mode_t); int __reg2 fstat (struct stat *buf); virtual int __reg2 link (const char *); diff --git a/winsup/cygwin/fhandler_process_fd.cc b/winsup/cygwin/fhandler_process_fd.cc index a33fd75..7d70ebe 100644 --- a/winsup/cygwin/fhandler_process_fd.cc +++ b/winsup/cygwin/fhandler_process_fd.cc @@ -97,7 +97,7 @@ fhandler_process_fd::fetch_fh (HANDLE &out_hdl, uint32_t flags) } fhandler_base * -fhandler_process_fd::fd_reopen (int flags) +fhandler_process_fd::fd_reopen (int flags, mode_t mode) { fhandler_base *fh; HANDLE hdl; @@ -106,7 +106,7 @@ fhandler_process_fd::fd_reopen (int flags) if (!fh) return NULL; fh->set_io_handle (hdl); - int ret = fh->open_with_arch (flags, 0); + int ret = fh->open_with_arch (flags, mode); CloseHandle (hdl); if (!ret) { diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 8a995e8..d1a1312 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1507,7 +1507,7 @@ open (const char *unix_path, int flags, ...) if (fh->dev () == FH_PROCESSFD && fh->pc.follow_fd_symlink ()) { /* Reopen file by descriptor */ - fh_file = fh->fd_reopen (flags); + fh_file = fh->fd_reopen (flags, mode & 07777); if (!fh_file) __leave; delete fh;