diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-02-13 11:36:05 +0900 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-02-13 23:36:23 +0900 |
commit | 73cd80c976e1bc4af5f63c02be94a112dd2cfecc (patch) | |
tree | 85fc23866505b3c4bdc1320d700573e10fe7bec0 | |
parent | a6ac7b413891b9fa4fce58bb1fb4729798b7c8a1 (diff) | |
download | newlib-73cd80c976e1bc4af5f63c02be94a112dd2cfecc.zip newlib-73cd80c976e1bc4af5f63c02be94a112dd2cfecc.tar.gz newlib-73cd80c976e1bc4af5f63c02be94a112dd2cfecc.tar.bz2 |
Cygwin: pty: Fix potential handle leak regarding CallNamedPipe().
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
-rw-r--r-- | winsup/cygwin/fhandler/pty.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc index c5c7921..d31d30b 100644 --- a/winsup/cygwin/fhandler/pty.cc +++ b/winsup/cygwin/fhandler/pty.cc @@ -936,6 +936,8 @@ fhandler_pty_slave::open (int flags, mode_t) errmsg = "can't call master, %E"; goto err; } + CloseHandle (repl.to_slave_nat); /* not used. */ + CloseHandle (repl.to_slave); /* not used. */ from_master_nat_local = repl.from_master_nat; from_master_local = repl.from_master; to_master_nat_local = repl.to_master_nat; @@ -1210,6 +1212,10 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) if (!CallNamedPipe (pipe, &req, sizeof req, &repl, sizeof repl, &len, 500)) return; /* What can we do? */ + CloseHandle (repl.from_master); /* not used. */ + CloseHandle (repl.to_master); /* not used. */ + CloseHandle (repl.to_slave_nat); /* not used. */ + CloseHandle (repl.to_slave); /* not used. */ CloseHandle (get_handle_nat ()); set_handle_nat (repl.from_master_nat); CloseHandle (get_output_handle_nat ()); @@ -3861,10 +3867,20 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp, if (!CallNamedPipe (pipe, &req, sizeof req, &repl, sizeof repl, &len, 500)) return; /* What can we do? */ + CloseHandle (repl.from_master_nat); /* not used. */ + CloseHandle (repl.from_master); /* not used. */ + CloseHandle (repl.to_master_nat); /* not used. */ + CloseHandle (repl.to_master); /* not used. */ if (dir == tty::to_nat) - to = repl.to_slave_nat; + { + CloseHandle (repl.to_slave); /* not used. */ + to = repl.to_slave_nat; + } else - to = repl.to_slave; + { + CloseHandle (repl.to_slave_nat); /* not used. */ + to = repl.to_slave; + } } UINT cp_from = 0, cp_to = 0; |