This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: PATCH: Fix TUI null pointer dereference
- From: Andrew STUBBS <andrew dot stubbs at st dot com>
- To: Jim Blandy <jimb at redhat dot com>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Mon, 24 Oct 2005 14:30:15 +0100
- Subject: Re: PATCH: Fix TUI null pointer dereference
- References: <4353B4A5.3010209@st.com> <vt24q7d416u.fsf@theseus.home.>
Jim Blandy wrote:
Andrew STUBBS <andrew.stubbs@st.com> writes:
Index: src/gdb/tui/tui-command.c
===================================================================
--- src.orig/gdb/tui/tui-command.c 2004-02-16 21:05:09.000000000 +0000
+++ src/gdb/tui/tui-command.c 2005-10-17 14:33:06.000000000 +0100
@@ -70,7 +70,7 @@ tui_dispatch_ctrl_char (unsigned int ch)
term = (char *) getenv ("TERM");
for (i = 0; (term && term[i]); i++)
term[i] = toupper (term[i]);
- if ((strcmp (term, "XTERM") == 0) && key_is_start_sequence (ch))
+ if (term && (strcmp (term, "XTERM") == 0) && key_is_start_sequence (ch))
{
unsigned int page_ch = 0;
unsigned int tmp_char;
How about wrapping the upcasing loop and the 'if' after it all in one
big 'if (term), starting right after the 'getenv ("TERM")', and then
simplifying the conditional in the upcasing loop?
How about the attached? Diff has made it look rather confusing, but I
assure you the only thing that has changed is the indenting and the
extra if.
Andrew Stubbs
2005-10-24 Andrew Stubbs <andrew.stubbs@st.com>
* tui/tui-command.c (tui_dispatch_ctrl_char): Test output of
getenv() before using it.
Index: src/gdb/tui/tui-command.c
===================================================================
--- src.orig/gdb/tui/tui-command.c 2005-10-24 13:58:38.000000000 +0100
+++ src/gdb/tui/tui-command.c 2005-10-24 14:11:02.000000000 +0100
@@ -67,34 +67,36 @@ tui_dispatch_ctrl_char (unsigned int ch)
** by keypad as a single char, so we must handle them here.
** Seems like a bug in the curses library?
*/
- term = (char *) getenv ("TERM");
- for (i = 0; (term && term[i]); i++)
- term[i] = toupper (term[i]);
- if ((strcmp (term, "XTERM") == 0) && key_is_start_sequence (ch))
+ if (term = (char *) getenv ("TERM"))
{
- unsigned int page_ch = 0;
- unsigned int tmp_char;
-
- tmp_char = 0;
- while (!key_is_end_sequence (tmp_char))
+ for (i = 0; term[i]; i++)
+ term[i] = toupper (term[i]);
+ if ((strcmp (term, "XTERM") == 0) && key_is_start_sequence (ch))
{
- tmp_char = (int) wgetch (w);
- if (tmp_char == ERR)
- {
- return ch;
- }
- if (!tmp_char)
- break;
- if (tmp_char == 53)
- page_ch = KEY_PPAGE;
- else if (tmp_char == 54)
- page_ch = KEY_NPAGE;
- else
+ unsigned int page_ch = 0;
+ unsigned int tmp_char;
+
+ tmp_char = 0;
+ while (!key_is_end_sequence (tmp_char))
{
- return 0;
+ tmp_char = (int) wgetch (w);
+ if (tmp_char == ERR)
+ {
+ return ch;
+ }
+ if (!tmp_char)
+ break;
+ if (tmp_char == 53)
+ page_ch = KEY_PPAGE;
+ else if (tmp_char == 54)
+ page_ch = KEY_NPAGE;
+ else
+ {
+ return 0;
+ }
}
+ ch_copy = page_ch;
}
- ch_copy = page_ch;
}
switch (ch_copy)