summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Brown <kbrown@cornell.edu>2019-07-24 11:29:53 -0400
committerKen Brown <kbrown@cornell.edu>2019-07-24 13:26:08 -0400
commit8a46b8ede22d707aae2dc2e0e53cbad3f26f029f (patch)
tree1c38806a0a8f9f8f818505e0d6a7278ba51757d0
parent280b21d373f7029f5cef078740dc1085c8a5e549 (diff)
downloadcygnal-8a46b8ede22d707aae2dc2e0e53cbad3f26f029f.tar.gz
cygnal-8a46b8ede22d707aae2dc2e0e53cbad3f26f029f.tar.bz2
cygnal-8a46b8ede22d707aae2dc2e0e53cbad3f26f029f.zip
Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative
Return -1 with EINVAL if pgid < 0. Previously tcsetpgrp() would blindly go ahead and set the pgid of the controlling terminal to a negative value, causing later calls to various functions to fail. For example, gdb has code like the following: tcsetpgrp (0, getpgid (inf->pid)); If getpgid (inf->pid) fails (returns -1), then this code would set the pgid of fd 0 to -1, so that some later calls to getpgid() would also return -1. This caused the problem reported here: https://cygwin.com/ml/cygwin/2019-07/msg00166.html.
-rw-r--r--winsup/cygwin/fhandler_termios.cc5
1 files changed, 5 insertions, 0 deletions
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)
{