From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75492 invoked by alias); 10 Feb 2020 15:07:30 -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 75450 invoked by uid 9078); 10 Feb 2020 15:07:30 -0000 Date: Mon, 10 Feb 2020 15:07:00 -0000 Message-ID: <20200210150730.75449.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: pty: Prevent potential errno overwriting. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 2de74af22be0ccf75f094caf48c8beb36a49d8c9 X-Git-Newrev: 2379142bc5d345421acb9e3ac86abcad0d7bf71e X-SW-Source: 2020-q1/txt/msg00061.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2379142bc5d345421acb9e3ac86abcad0d7bf71e commit 2379142bc5d345421acb9e3ac86abcad0d7bf71e Author: Takashi Yano Date: Mon Feb 10 20:42:45 2020 +0900 Cygwin: pty: Prevent potential errno overwriting. - In push_to_pcon_screenbuffer(), open() and ioctl() are called. Since push_to_pcon_screenbuffer() is called in read() and write(), errno which is set in read() and write() code may be overwritten in open() or ioctl() call. This patch prevent this situation. Diff: --- winsup/cygwin/fhandler_tty.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 260776a..cfd4b1c 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1412,10 +1412,13 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len, while (!GetConsoleMode (get_output_handle (), &dwMode)) { termios_printf ("GetConsoleMode failed, %E"); + int errno_save = errno; /* Re-open handles */ this->open (0, 0); /* Fix pseudo console window size */ this->ioctl (TIOCSWINSZ, &get_ttyp ()->winsize); + if (errno != errno_save) + set_errno (errno_save); if (++retry_count > 3) goto cleanup; }