public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pty: Check response for CSI6n more strictly.
@ 2020-12-16  9:10 Takashi Yano
  2020-12-16  9:39 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2020-12-16  9:10 UTC (permalink / raw)
  To: cygwin-patches

- Previous code to read response for CSI6n allows invalid response
  such as "CSI Pl; Pc H" other than correct response "CSI Pl; Pc R".
  With this patch, the response is checked more strictly.
---
 winsup/cygwin/fhandler_tty.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5f38ca8d3..77d9d9b47 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2682,7 +2682,9 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
 	  len -= n;
 	  *p = '\0';
 	  char *p1 = strrchr (buf, '\033');
-	  if (p1 == NULL || sscanf (p1, "\033[%d;%dR", &y1, &x1) != 2)
+	  char c;
+	  if (p1 == NULL || sscanf (p1, "\033[%d;%d%c", &y1, &x1, &c) != 3
+	      || c != 'R')
 	    continue;
 	  wait_cnt = 0;
 	  break;
@@ -2715,7 +2717,9 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
       len -= n;
       *p = '\0';
       char *p2 = strrchr (buf, '\033');
-      if (p2 == NULL || sscanf (p2, "\033[%d;%dR", &y2, &x2) != 2)
+      char c;
+      if (p2 == NULL || sscanf (p2, "\033[%d;%d%c", &y2, &x2, &c) != 3
+	  || c != 'R')
 	continue;
       break;
     }
-- 
2.29.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: pty: Check response for CSI6n more strictly.
  2020-12-16  9:10 [PATCH] Cygwin: pty: Check response for CSI6n more strictly Takashi Yano
@ 2020-12-16  9:39 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-12-16  9:39 UTC (permalink / raw)
  To: cygwin-patches

On Dec 16 18:10, Takashi Yano via Cygwin-patches wrote:
> - Previous code to read response for CSI6n allows invalid response
>   such as "CSI Pl; Pc H" other than correct response "CSI Pl; Pc R".
>   With this patch, the response is checked more strictly.
> ---
>  winsup/cygwin/fhandler_tty.cc | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 5f38ca8d3..77d9d9b47 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -2682,7 +2682,9 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
>  	  len -= n;
>  	  *p = '\0';
>  	  char *p1 = strrchr (buf, '\033');
> -	  if (p1 == NULL || sscanf (p1, "\033[%d;%dR", &y1, &x1) != 2)
> +	  char c;
> +	  if (p1 == NULL || sscanf (p1, "\033[%d;%d%c", &y1, &x1, &c) != 3
> +	      || c != 'R')
>  	    continue;
>  	  wait_cnt = 0;
>  	  break;
> @@ -2715,7 +2717,9 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
>        len -= n;
>        *p = '\0';
>        char *p2 = strrchr (buf, '\033');
> -      if (p2 == NULL || sscanf (p2, "\033[%d;%dR", &y2, &x2) != 2)
> +      char c;
> +      if (p2 == NULL || sscanf (p2, "\033[%d;%d%c", &y2, &x2, &c) != 3
> +	  || c != 'R')
>  	continue;
>        break;
>      }
> -- 
> 2.29.2

Pushed.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-16  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16  9:10 [PATCH] Cygwin: pty: Check response for CSI6n more strictly Takashi Yano
2020-12-16  9:39 ` Corinna Vinschen

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).