binutils-gdb/gdb/tui
Shahab Vahedi cbfa858117 GDB: Fix the overflow in addr/line_is_displayed()
In tui_disasm_window::addr_is_displayed(), there can be situations
where "content" is empty. For instance, it can happen when the
"content" was not filled in tui_disasm_window::set_contents(),
because tui_disassemble() threw an exception. Usually this exception
is the result of fetching invalid PC addresses like the ones beyond
the end of the program.

Having "content.size ()" zero leads to an overflow in this condition
check inside tui_disasm_window::addr_is_displayed():

  int i = 0;
  while (i < content.size () - threshold ...) {
    ... content[i] ...
  }

"threshold" is 2 and there are times that "content.size ()" is 0.
This results into an overflow and the loop is entered whereas it
should have been skipped. Finally, "content[i]" access leads to
a segmentation fault.

Same problem applies to tui_source_window::line_is_displayed().

The issue has been discussed at length in bug 25345:
  https://sourceware.org/bugzilla/show_bug.cgi?id=25345

This commit avoids the segmentation faults with an early check:

  if (content.size () < SCROLL_THRESHOLD)
    return false;

Moreover, those functions have been overhauled to a leaner code.

gdb/ChangeLog:
2020-01-06  Shahab Vahedi  <shahab@synopsys.com>

	* tui/tui-disasm.c (tui_disasm_window::addr_is_displayed): Avoid
	overflow by an early check of content vs threshold.
        * tui/tui-source.c (tui_source_window::line_is_displayed):
	Likewise.
2020-01-06 19:47:20 +00:00
..
ChangeLog-1998-2003
tui-command.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-command.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-data.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-data.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-disasm.c GDB: Fix the overflow in addr/line_is_displayed() 2020-01-06 19:47:20 +00:00
tui-disasm.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-file.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-file.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-hooks.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-hooks.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-interp.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-io.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-io.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-layout.c gdb: use tui_set_layout not show_layout to fix window focus 2020-01-05 21:49:05 +00:00
tui-layout.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-out.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-out.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-regs.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-regs.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-source.c GDB: Fix the overflow in addr/line_is_displayed() 2020-01-06 19:47:20 +00:00
tui-source.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-stack.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-stack.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-win.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-win.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-wingeneral.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-wingeneral.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-winsource.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui-winsource.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
tui.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00