public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] inflow.c: Do not leak tty.
@ 2021-05-14 11:33 Alexandra Hájková
  2021-05-14 13:22 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandra Hájková @ 2021-05-14 11:33 UTC (permalink / raw)
  To: gdb-patches; +Cc: Alexandra Hájková

From: Alexandra Hájková <ahajkova@redhat.com>

In a case open() returns 0 tty might be leaked. While 0 should be
stdin (and therefore is an unlikely return value from open()), it's
still the case that the test should be for non-negative return values
from open().

gdb/ChangeLog:

2021-11-05 Alexandra Hájková <ahajkova@redhat.com>

	* inflow.c (new_tty): Do not leak tty.
---
 gdb/inflow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/inflow.c b/gdb/inflow.c
index 994c73e40ee..d241540c4cd 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -808,7 +808,7 @@ new_tty (void)
      systems (SVR4 for example), this may cause a SIGTTOU, so temporarily
      ignore SIGTTOU.  */
   tty = open ("/dev/tty", O_RDWR);
-  if (tty > 0)
+  if (tty >= 0)
     {
       scoped_ignore_sigttou ignore_sigttou;
 
-- 
2.26.3


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

* Re: [PATCH] inflow.c: Do not leak tty.
  2021-05-14 11:33 [PATCH] inflow.c: Do not leak tty Alexandra Hájková
@ 2021-05-14 13:22 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2021-05-14 13:22 UTC (permalink / raw)
  To: Alexandra Hájková, gdb-patches

On 2021-05-14 7:33 a.m., Alexandra Hájková via Gdb-patches wrote:
> From: Alexandra Hájková <ahajkova@redhat.com>
> 
> In a case open() returns 0 tty might be leaked. While 0 should be
> stdin (and therefore is an unlikely return value from open()), it's
> still the case that the test should be for non-negative return values
> from open().

That indeed looks like a little brain fart from when the code was
written, the patch LGTM.

Simon

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

end of thread, other threads:[~2021-05-14 13:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 11:33 [PATCH] inflow.c: Do not leak tty Alexandra Hájková
2021-05-14 13:22 ` Simon Marchi

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