diff options
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/minsyms.c | 18 |
2 files changed, 15 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4ef8a5c..0c658e2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-03-24 Philippe Waroquiers <philippe.waroquiers@skynet.be> + Tom Tromey <tromey@adacore.com> + + * minsyms.c (minimal_symbol_upper_bound): Fix buffer overflow. + 2019-03-26 Joel Brobecker <brobecker@adacore.com> * gdb-gdb.py.in (StructMainTypePrettyPrinter.bound_img): New method. diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 777f545..51b65f5 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -1445,11 +1445,10 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc) CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym) { - int i; short section; struct obj_section *obj_section; CORE_ADDR result; - struct minimal_symbol *msymbol; + struct minimal_symbol *iter, *msymbol; gdb_assert (minsym.minsym != NULL); @@ -1464,21 +1463,24 @@ minimal_symbol_upper_bound (struct bound_minimal_symbol minsym) other sections, to find the next symbol in this section with a different address. */ + struct minimal_symbol *past_the_end + = (minsym.objfile->per_bfd->msymbols.get () + + minsym.objfile->per_bfd->minimal_symbol_count); msymbol = minsym.minsym; section = MSYMBOL_SECTION (msymbol); - for (i = 1; MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++) + for (iter = msymbol + 1; iter != past_the_end; ++iter) { - if ((MSYMBOL_VALUE_RAW_ADDRESS (msymbol + i) + if ((MSYMBOL_VALUE_RAW_ADDRESS (iter) != MSYMBOL_VALUE_RAW_ADDRESS (msymbol)) - && MSYMBOL_SECTION (msymbol + i) == section) + && MSYMBOL_SECTION (iter) == section) break; } obj_section = MSYMBOL_OBJ_SECTION (minsym.objfile, minsym.minsym); - if (MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL - && (MSYMBOL_VALUE_ADDRESS (minsym.objfile, msymbol + i) + if (iter != past_the_end + && (MSYMBOL_VALUE_ADDRESS (minsym.objfile, iter) < obj_section_endaddr (obj_section))) - result = MSYMBOL_VALUE_ADDRESS (minsym.objfile, msymbol + i); + result = MSYMBOL_VALUE_ADDRESS (minsym.objfile, iter); else /* We got the start address from the last msymbol in the objfile. So the end address is the end of the section. */ |