[PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.

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

[PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.

Takashi Yano
- Even with commit fe512b2b12a2cea8393d14f038dc3914b1bf3f60, pty
  still has a problem in ESC[?3h and ESC[?3l handling if invalid
  sequence such as ESC[?$ is sent. This patch fixes the issue.
---
 winsup/cygwin/fhandler_tty.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 8c3a6e72e..f10f0fc61 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1263,7 +1263,7 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len)
     {
       p0 += 3;
       bool exist_arg_3 = false;
-      while (p0 < buf + nlen && !isalpha (*p0))
+      while (p0 < buf + nlen && (isdigit (*p0) || *p0 == ';'))
  {
   int arg = 0;
   while (p0 < buf + nlen && isdigit (*p0))
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.

Corinna Vinschen-2
On Dec 19 20:03, Takashi Yano wrote:

> - Even with commit fe512b2b12a2cea8393d14f038dc3914b1bf3f60, pty
>   still has a problem in ESC[?3h and ESC[?3l handling if invalid
>   sequence such as ESC[?$ is sent. This patch fixes the issue.
> ---
>  winsup/cygwin/fhandler_tty.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index 8c3a6e72e..f10f0fc61 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -1263,7 +1263,7 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const char *ptr, size_t len)
>      {
>        p0 += 3;
>        bool exist_arg_3 = false;
> -      while (p0 < buf + nlen && !isalpha (*p0))
> +      while (p0 < buf + nlen && (isdigit (*p0) || *p0 == ';'))
>   {
>    int arg = 0;
>    while (p0 < buf + nlen && isdigit (*p0))
> --
> 2.21.0
Pushed.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.

cygwin-patches mailing list
Just noticed that in the patch below and couldn't help it, sorry..

Things like

char* p0;

and later:

isdigit(*p0))  or  isalpha(*p0)

are usually not a good (correct) way of coding, because of possible sign extension of *p0
which you normally wouldn't want to have (remember the ctype calls/macros actually expect
an "int", not a character, input).  So it should be either "unsigned char* p0" or
"isdigit((unsigned char)(*p0))", generally.

> -----Original Message-----
> From: [hidden email] <[hidden email]> On
> Behalf Of Corinna Vinschen
> Sent: Thursday, December 19, 2019 6:29 AM
> To: [hidden email]
> Subject: Re: [PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.
>
> On Dec 19 20:03, Takashi Yano wrote:
> > - Even with commit fe512b2b12a2cea8393d14f038dc3914b1bf3f60, pty
> >   still has a problem in ESC[?3h and ESC[?3l handling if invalid
> >   sequence such as ESC[?$ is sent. This patch fixes the issue.
> > ---
> >  winsup/cygwin/fhandler_tty.cc | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> > index 8c3a6e72e..f10f0fc61 100644
> > --- a/winsup/cygwin/fhandler_tty.cc
> > +++ b/winsup/cygwin/fhandler_tty.cc
> > @@ -1263,7 +1263,7 @@ fhandler_pty_slave::push_to_pcon_screenbuffer (const
> char *ptr, size_t len)
> >      {
> >        p0 += 3;
> >        bool exist_arg_3 = false;
> > -      while (p0 < buf + nlen && !isalpha (*p0))
> > +      while (p0 < buf + nlen && (isdigit (*p0) || *p0 == ';'))
> >   {
> >    int arg = 0;
> >    while (p0 < buf + nlen && isdigit (*p0))
> > --
> > 2.21.0
>
> Pushed.
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Fix ESC[?3h and ESC[?3l handling again.

Takashi Yano
On Thu, 19 Dec 2019 15:50:07 +0000
"Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin-patches" wrote:

> Just noticed that in the patch below and couldn't help it, sorry..
>
> Things like
>
> char* p0;
>
> and later:
>
> isdigit(*p0))  or  isalpha(*p0)
>
> are usually not a good (correct) way of coding, because of possible sign extension of *p0
> which you normally wouldn't want to have (remember the ctype calls/macros actually expect
> an "int", not a character, input).  So it should be either "unsigned char* p0" or
> "isdigit((unsigned char)(*p0))", generally.

Thanks for the advice. In general, you are right.

However, in cygwin, ALLOW_NEGATIVE_CTYPE_INDEX is defined
in ctype library in newlib, and the lookup table is extended
in the negative direction.

So, in terms of results, the code works as expected.

--
Takashi Yano <[hidden email]>