This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix crash on NULL rl_prompt


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]