From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22972 invoked by alias); 29 Mar 2010 23:40:40 -0000 Received: (qmail 22952 invoked by uid 22791); 29 Mar 2010 23:40:38 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Mar 2010 23:40:32 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2TNeVor030866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Mar 2010 19:40:31 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2TNeRol017230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 29 Mar 2010 19:40:29 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id o2TNeRct024217 for ; Tue, 30 Mar 2010 01:40:27 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id o2TNeRWU024216 for gdb-patches@sourceware.org; Tue, 30 Mar 2010 01:40:27 +0200 Date: Mon, 29 Mar 2010 23:40:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix crash on NULL rl_prompt Message-ID: <20100329234026.GA23895@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg01034.txt.bz2 Hi, https://bugzilla.redhat.com/attachment.cgi?id=401527 #1 in xstrdup (s=0x0) at ../../libiberty/xstrdup.c:33 #2 in tui_prep_terminal (notused1=1) at ../../gdb/tui/tui-io.c:292 #3 in _rl_callback_newline () at ../callback.c:82 #4 in gdb_do_one_event (data=0x0) at ../../gdb/event-loop.c:468 #5 in catch_errors (func=0x8177e60 , #6 in tui_command_loop #7 in current_interp_command_loop #8 in captured_command_loop #9 in catch_errors #10 in captured_main #11 in catch_errors #12 in gdb_main #13 in main I have not found how to reproduce it, normally when GDB calls tui_prep_terminal it has rl_prompt set to non-NULL. But NULL rl_prompt is a valid state for readline and GDB itself even sets it temporarily to NULL in tui_setup_io (1) (just tui_prep_terminal is not called in such case) so I find it fragile to crash on NULL rl_prompt. GDB can handle NULL tui_rl_saved_prompt. BTW don't you think xstrdup (NULL) should == NULL? Like xmalloc (0) == NULL. No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu. Thanks, Jan 2010-03-30 Jan Kratochvil * tui/tui-io.c (tui_prep_terminal): Permit NULL rl_prompt. --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -289,7 +289,10 @@ tui_prep_terminal (int notused1) (we can't use gdb_prompt() due to secondary prompts and can't use rl_prompt because it points to an alloca buffer). */ xfree (tui_rl_saved_prompt); - tui_rl_saved_prompt = xstrdup (rl_prompt); + if (rl_prompt) + tui_rl_saved_prompt = xstrdup (rl_prompt); + else + tui_rl_saved_prompt = NULL; } /* Readline callback to restore the terminal. It is called once each