Mark Wielaard ee9108
Index: coregrind/m_debuginfo/readdwarf.c
Mark Wielaard ee9108
===================================================================
Mark Wielaard c728a3
--- valgrind/coregrind/m_debuginfo/readdwarf.c	(revision 12871)
Mark Wielaard c728a3
+++ valgrind/coregrind/m_debuginfo/readdwarf.c	(working copy)
Mark Wielaard ee9108
@@ -945,11 +945,11 @@
Mark Wielaard ee9108
 /* Return abbrev for given code 
Mark Wielaard ee9108
  * Returned pointer points to the tag
Mark Wielaard ee9108
  * */
Mark Wielaard ee9108
-static UChar* lookup_abbrev( UChar* p, UInt acode )
Mark Wielaard ee9108
+static UChar* lookup_abbrev( UChar* p, UInt acode, UChar* end_img )
Mark Wielaard ee9108
 {
Mark Wielaard ee9108
    UInt code;
Mark Wielaard ee9108
    UInt name;
Mark Wielaard ee9108
-   for( ; ; ) {
Mark Wielaard ee9108
+   while( p < end_img ) {
Mark Wielaard ee9108
       code = read_leb128U( &p );
Mark Wielaard ee9108
       if ( code == acode )
Mark Wielaard ee9108
          return p;
Mark Wielaard ee9108
@@ -959,7 +959,7 @@
Mark Wielaard ee9108
          name = read_leb128U( &p ); /* name */
Mark Wielaard ee9108
          read_leb128U( &p );   /* form */
Mark Wielaard ee9108
       }
Mark Wielaard ee9108
-      while( name != 0 ); /* until name == form == 0 */
Mark Wielaard ee9108
+      while( name != 0 && p < end_img ); /* until name == form == 0 */
Mark Wielaard ee9108
    }
Mark Wielaard ee9108
    return NULL;
Mark Wielaard ee9108
 }
Mark Wielaard ee9108
@@ -985,6 +985,7 @@
Mark Wielaard ee9108
 void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
Mark Wielaard ee9108
                                   UChar*    unitblock_img,
Mark Wielaard ee9108
                                   UChar*    debugabbrev_img,
Mark Wielaard ee9108
+                                  Word      debug_abbv_sz,
Mark Wielaard ee9108
                                   UChar*    debugstr_img,
Mark Wielaard ee9108
                                   UChar*    debugstr_alt_img )
Mark Wielaard ee9108
 {
Mark Wielaard ee9108
@@ -1046,7 +1047,12 @@
Mark Wielaard ee9108
           * not triggered since we shortcut the parsing once we have
Mark Wielaard ee9108
           * read the compile_unit block.  This should only occur when
Mark Wielaard ee9108
           * level > 0 */
Mark Wielaard ee9108
-         abbrev_img = lookup_abbrev( debugabbrev_img + atoffs, acode );
Mark Wielaard ee9108
+         abbrev_img = lookup_abbrev( debugabbrev_img + atoffs, acode,
Mark Wielaard ee9108
+				     debugabbrev_img + debug_abbv_sz );
Mark Wielaard ee9108
+	 if ( abbrev_img == NULL ) {
Mark Wielaard ee9108
+	     VG_(printf)( "### unknown abbrev 0x%x\n", acode );
Mark Wielaard ee9108
+	     break;
Mark Wielaard ee9108
+	 }
Mark Wielaard ee9108
       }
Mark Wielaard ee9108
 
Mark Wielaard ee9108
       tag = read_leb128U( &abbrev_img );
Mark Wielaard ee9108
@@ -1056,7 +1062,7 @@
Mark Wielaard ee9108
          level++;
Mark Wielaard ee9108
 
Mark Wielaard ee9108
       /* And loop on entries */
Mark Wielaard ee9108
-      for ( ; ; ) {
Mark Wielaard ee9108
+      while( p < end_img ) {
Mark Wielaard ee9108
          /* Read entry definition */
Mark Wielaard ee9108
          UInt  name, form;
Mark Wielaard ee9108
          ULong cval = -1LL;  /* Constant value read */
Mark Wielaard 3bd489
@@ -1221,4 +1227,4 @@
Mark Wielaard ee9108
       read_unitinfo_dwarf2( &ui, block_img, 
Mark Wielaard ee9108
-                                 debug_abbv_img, debug_str_img,
Mark Wielaard ee9108
+                                 debug_abbv_img, debug_abbv_sz, debug_str_img,
Mark Wielaard ee9108
                                  debug_str_alt_img );
Mark Wielaard ee9108
       if (0)
Mark Wielaard ee9108
          VG_(printf)( "   => LINES=0x%llx    NAME=%s     DIR=%s\n",