From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id A413D3890418; Mon, 22 Feb 2021 09:50:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A413D3890418 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Fix segfault caused when tcflush() is called. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano via Cygwin-patches X-Git-Refname: refs/heads/master X-Git-Oldrev: 246121534a291d70b1a53f1be85e392981f25e9f X-Git-Newrev: 18b91fbe580e747edf0f7ef8edbec4df07bc7245 Message-Id: <20210222095038.A413D3890418@sourceware.org> Date: Mon, 22 Feb 2021 09:50:38 +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: Mon, 22 Feb 2021 09:50:38 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=18b91fbe580e747edf0f7ef8edbec4df07bc7245 commit 18b91fbe580e747edf0f7ef8edbec4df07bc7245 Author: Takashi Yano via Cygwin-patches Date: Sun Feb 21 07:45:16 2021 +0900 Cygwin: pty: Fix segfault caused when tcflush() is called. - After commit 253352e796ff9ec9a447e5375f5bc3e2b92b5293, mc (midnight commander) crashes with segfault if the shell is bash. This is due to NULL pointer access in read(). This patch fixes the issue. Addresses:: https://cygwin.com/pipermail/cygwin/2021-February/247870.html Diff: --- winsup/cygwin/fhandler_tty.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index d30041af1..3fcaa8277 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1474,8 +1474,11 @@ wait_retry: out: termios_printf ("%d = read(%p, %lu)", totalread, ptr, len); len = (size_t) totalread; - bool saw_eol = totalread > 0 && strchr ("\r\n", ptr0[totalread -1]); - mask_switch_to_pcon_in (false, saw_eol); + if (ptr0) + { /* Not tcflush() */ + bool saw_eol = totalread > 0 && strchr ("\r\n", ptr0[totalread -1]); + mask_switch_to_pcon_in (false, saw_eol); + } } int