Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Fix crash on NULL rl_prompt
@ 2010-03-29 23:40 Jan Kratochvil
  2010-03-30 15:57 ` Tom Tromey
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kratochvil @ 2010-03-29 23:40 UTC (permalink / raw)
  To: gdb-patches

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 <gdb_do_one_event>, 
#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  <jan.kratochvil@redhat.com>

	* 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


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

end of thread, other threads:[~2010-03-31 21:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-29 23:40 [patch] Fix crash on NULL rl_prompt Jan Kratochvil
2010-03-30 15:57 ` Tom Tromey
2010-03-30 16:12   ` Pedro Alves
2010-03-30 16:23     ` Tom Tromey
2010-03-30 16:41       ` Pedro Alves
2010-03-30 17:05         ` Jan Kratochvil
2010-03-30 17:13           ` Tom Tromey
2010-03-30 17:25           ` Pedro Alves
2010-03-30 17:29             ` Jan Kratochvil
2010-03-30 17:55               ` Pedro Alves
2010-03-31 21:27                 ` [cancel] " Jan Kratochvil
2010-03-30 17:31             ` Tom Tromey
2010-03-30 20:50             ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox