This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Avoid indexing std::vector past the end


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=47fea877452b84b94ac6ffb26f194f12845526fa

commit 47fea877452b84b94ac6ffb26f194f12845526fa
Author: Ruslan Kabatsayev <b7.10110111@gmail.com>
Date:   Sat Dec 30 22:14:41 2017 +0300

    Avoid indexing std::vector past the end
    
    The code here wants to find address of an element, and often this
    element is one past the end of std::vector. Dereferencing that element
    leads to undefined behavior, so it's better to simply use pointer
    arithmetic instead of taking address of invalid dereference.
    
    gdb/ChangeLog:
    
    	* psymtab.c (recursively_search_psymtabs): Use pointer arithmetic
    	instead of dereferencing std::vector past the end.

Diff:
---
 gdb/ChangeLog | 5 +++++
 gdb/psymtab.c | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index edb3cd4..aaadf14 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-12-31  Ruslan Kabatsayev  <b7.10110111@gmail.com>
+
+	* psymtab.c (recursively_search_psymtabs): Use pointer arithmetic
+	instead of dereferencing std::vector past the end.
+
 2017-12-30  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* common/diagnostics.h
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index c87ef25..1271e18 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1337,21 +1337,21 @@ recursively_search_psymtabs
     }
 
   partial_symbol **gbound
-    = &objfile->global_psymbols[ps->globals_offset + ps->n_global_syms];
+    = objfile->global_psymbols.data () + ps->globals_offset + ps->n_global_syms;
   partial_symbol **sbound
-    = &objfile->static_psymbols[ps->statics_offset + ps->n_static_syms];
+    = objfile->static_psymbols.data () + ps->statics_offset + ps->n_static_syms;
   partial_symbol **bound = gbound;
 
   /* Go through all of the symbols stored in a partial
      symtab in one loop.  */
-  partial_symbol **psym = &objfile->global_psymbols[ps->globals_offset];
+  partial_symbol **psym = objfile->global_psymbols.data () + ps->globals_offset;
   while (keep_going)
     {
       if (psym >= bound)
 	{
 	  if (bound == gbound && ps->n_static_syms != 0)
 	    {
-	      psym = &objfile->static_psymbols[ps->statics_offset];
+	      psym = objfile->static_psymbols.data () + ps->statics_offset;
 	      bound = sbound;
 	    }
 	  else


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]