[PATCH] Cygwin: pty: Prevent potential errno overwriting.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Cygwin: pty: Prevent potential errno overwriting.

Takashi Yano
- 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.
---
 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 260776a56..cfd4b1c44 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;
     }
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Prevent potential errno overwriting.

Corinna Vinschen-2
On Feb 10 20:42, Takashi Yano wrote:

> - 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.
> ---
>  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 260776a56..cfd4b1c44 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;
>      }
> --
> 2.21.0

Pushed.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment