This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2] GDB: Fix the overflow in addr_is_displayed()
- From: Shahab Vahedi <shahab dot vahedi at gmail dot com>
- To: gdb-patches at sourceware dot org
- Cc: Shahab Vahedi <shahab at synopsys dot com>, Claudiu Zissulescu <claziss at synopsys dot com>, Francois Bedard <fbedard at synopsys dot com>
- Date: Mon, 6 Jan 2020 11:26:49 +0100
- Subject: [PATCH v2] GDB: Fix the overflow in addr_is_displayed()
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
As a bonus, a few trailing spaces are also removed.
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.
* tui/tui-disasm.c: Remove trailing spaces.
---
gdb/tui/tui-disasm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index c72b50730b0..68744cc61e3 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -43,7 +43,7 @@
#include "gdb_curses.h"
-struct tui_asm_line
+struct tui_asm_line
{
CORE_ADDR addr;
std::string addr_string;
@@ -150,7 +150,7 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
CORE_ADDR last_addr;
int pos;
struct bound_minimal_symbol msymbol;
-
+
/* Find backward an address which is a symbol and for which
disassembling from that address will fill completely the
window. */
@@ -176,7 +176,7 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
do
{
CORE_ADDR next_addr;
-
+
pos++;
if (pos >= max_lines)
pos = 0;
@@ -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() - 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