[PATCH] Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative

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

[PATCH] Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative

Ken Brown-6
Return -1 with EINVAL if pgid < 0.  This fixes the gdb problem
reported here:

  https://cygwin.com/ml/cygwin/2019-07/msg00166.html
---
 winsup/cygwin/fhandler_termios.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
index 4ce53433a..5b0ba5603 100644
--- a/winsup/cygwin/fhandler_termios.cc
+++ b/winsup/cygwin/fhandler_termios.cc
@@ -69,6 +69,11 @@ fhandler_termios::tcsetpgrp (const pid_t pgid)
       set_errno (EPERM);
       return -1;
     }
+  else if (pgid < 0)
+    {
+      set_errno (EINVAL);
+      return -1;
+    }
   int res;
   while (1)
     {
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative

Corinna Vinschen-2
On Jul 24 15:34, Ken Brown wrote:
> Return -1 with EINVAL if pgid < 0.  This fixes the gdb problem
> reported here:

Why does it fix the issue?

>   https://cygwin.com/ml/cygwin/2019-07/msg00166.html
> ---
>  winsup/cygwin/fhandler_termios.cc | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
> index 4ce53433a..5b0ba5603 100644
> --- a/winsup/cygwin/fhandler_termios.cc
> +++ b/winsup/cygwin/fhandler_termios.cc
> @@ -69,6 +69,11 @@ fhandler_termios::tcsetpgrp (const pid_t pgid)
>        set_errno (EPERM);
>        return -1;
>      }
> +  else if (pgid < 0)
> +    {
> +      set_errno (EINVAL);
> +      return -1;
> +    }
>    int res;
>    while (1)
>      {
> --
> 2.21.0
Looks good with GDB 8.2.1.  A bit of description why this fixes the
problem and it's GTG.

Unfortunately it doesn't fix what I'm seeing under GDB 8.1.1, but I'm
more and more convinced this is GDB's fault.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

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

Re: [PATCH] Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative

Jon TURNEY
In reply to this post by Ken Brown-6
On 24/07/2019 16:34, Ken Brown wrote:
> Return -1 with EINVAL if pgid < 0.  This fixes the gdb problem
> reported here:
>
>    https://cygwin.com/ml/cygwin/2019-07/msg00166.html

Thanks.

> ---
>   winsup/cygwin/fhandler_termios.cc | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
> index 4ce53433a..5b0ba5603 100644
> --- a/winsup/cygwin/fhandler_termios.cc
> +++ b/winsup/cygwin/fhandler_termios.cc
> @@ -69,6 +69,11 @@ fhandler_termios::tcsetpgrp (const pid_t pgid)
>         set_errno (EPERM);
>         return -1;
>       }
> +  else if (pgid < 0)
> +    {
> +      set_errno (EINVAL);
> +      return -1;
> +    }
>     int res;
>     while (1)
>       {
>

I guess there's some additional validation missing somewhere (that pgid
is a valid process group id, which -1 can never be), but I think this is
more than adequate for the moment.