public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: pty: Prevent potential errno overwriting.
Date: Mon, 10 Feb 2020 15:07:00 -0000	[thread overview]
Message-ID: <20200210150730.75449.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2379142bc5d345421acb9e3ac86abcad0d7bf71e

commit 2379142bc5d345421acb9e3ac86abcad0d7bf71e
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
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;
     }


                 reply	other threads:[~2020-02-10 15:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200210150730.75449.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).