Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* [PATCH] GDB: Fix the overflow in addr_is_displayed()
@ 2020-01-04 11:43 Shahab Vahedi
  2020-01-06  0:30 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Shahab Vahedi @ 2020-01-04 11:43 UTC (permalink / raw)
  To: gdb-patches; +Cc: gdb, Shahab Vahedi, Claudiu Zissulescu, Francois Bedard

From: Shahab Vahedi <shahab@synopsys.com>

In a corner case scenario, where the height of the assembly TUI is
bigger than the number of instructions in the whole program, GDB
dumps core. The problem roots in this condition check:

  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.

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

gdb/ChangeLog:
2020-01-04  Shahab Vahedi  <shahab@synopsys.com>
        * tui/tui-disasm.c (tui_disasm_window::addr_is_displayed):
        Treat "content.size()" as "int" to avoid overflow.
---
 gdb/tui/tui-disasm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index c72b50730b0..a0921eb09d1 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -349,10 +349,10 @@ bool
 tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const
 {
   bool is_displayed = false;
-  int threshold = SCROLL_THRESHOLD;
+  int nr_of_lines = int(content.size()) - int(SCROLL_THRESHOLD);
 
   int i = 0;
-  while (i < content.size () - threshold && !is_displayed)
+  while (i < nr_of_lines && !is_displayed)
     {
       is_displayed
 	= (content[i].line_or_addr.loa == LOA_ADDRESS
-- 
2.24.1


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

end of thread, other threads:[~2020-01-06  0:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 11:43 [PATCH] GDB: Fix the overflow in addr_is_displayed() Shahab Vahedi
2020-01-06  0:30 ` Andrew Burgess

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