From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 0FB0E385802F; Fri, 4 Mar 2022 13:37:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FB0E385802F Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: pty: Fix a possible race issue in initialization of pcon. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 380e61dabe6cd5502046db425ff40815086b154a X-Git-Newrev: 09a54135cecacc2fcdc844fcf12a73c8191439e0 Message-Id: <20220304133712.0FB0E385802F@sourceware.org> Date: Fri, 4 Mar 2022 13:37:12 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 13:37:12 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D09a54135cec= acc2fcdc844fcf12a73c8191439e0 commit 09a54135cecacc2fcdc844fcf12a73c8191439e0 Author: Takashi Yano Date: Fri Mar 4 22:02:35 2022 +0900 Cygwin: pty: Fix a possible race issue in initialization of pcon. =20 - Currently, tty::pcon_start flag is cleared before transfer_input() in master::write(), however, the code in setup_pseudoconsole() waits for transfer_input() using tty::pcon_start. This possibly causes the race issue. The patch fixes this potential issue. Diff: --- winsup/cygwin/fhandler_tty.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 2d7e2cf69..a97460660 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -3297,7 +3297,8 @@ fhandler_pty_slave::setup_pseudoconsole (bool nopcon) get_ttyp ()->pcon_start_pid =3D myself->pid; WriteFile (get_output_handle (), "\033[6n", 4, &n, NULL); ReleaseMutex (input_mutex); - while (get_ttyp ()->pcon_start) + while (get_ttyp ()->pcon_start_pid) + /* wait for completion of transfer_input() in master::write(). */ Sleep (1); } /* Attach to the pseudo console which already exits. */