Mark Wielaard ee9108
Index: coregrind/m_debuginfo/readdwarf.c
Mark Wielaard ee9108
===================================================================
Mark Wielaard ee9108
--- valgrind-3.8.0/coregrind/m_debuginfo/readdwarf.c	(revision 12871)
Mark Wielaard ee9108
+++ valgrind-3.8.0/coregrind/m_debuginfo/readdwarf.c	(working copy)
Mark Wielaard ee9108
@@ -1115,7 +1115,8 @@
Mark Wielaard ee9108
             case 0x01: /* FORM_addr */      p += addr_size; break;
Mark Wielaard ee9108
             case 0x03: /* FORM_block2 */    p += ML_(read_UShort)(p) + 2; break;
Mark Wielaard ee9108
             case 0x04: /* FORM_block4 */    p += ML_(read_UInt)(p) + 4; break;
Mark Wielaard ee9108
-            case 0x09: /* FORM_block */     p += read_leb128U( &p ); break;
Mark Wielaard ee9108
+            case 0x09: /* FORM_block */     /* fallthrough */
Mark Wielaard ee9108
+            case 0x18: /* FORM_exprloc */   { ULong block_len = read_leb128U( &p ); p += block_len; break; }
Mark Wielaard ee9108
             case 0x0a: /* FORM_block1 */    p += *p + 1; break;
Mark Wielaard ee9108
             case 0x0c: /* FORM_flag */      p++; break;
Mark Wielaard ee9108
             case 0x0d: /* FORM_sdata */     read_leb128S( &p ); break;
Mark Wielaard ee9108
@@ -1126,7 +1127,6 @@
Mark Wielaard ee9108
             case 0x13: /* FORM_ref4 */      p += 4; break;
Mark Wielaard ee9108
             case 0x14: /* FORM_ref8 */      p += 8; break;
Mark Wielaard ee9108
             case 0x15: /* FORM_ref_udata */ read_leb128U( &p ); break;
Mark Wielaard ee9108
-            case 0x18: /* FORM_exprloc */   p += read_leb128U( &p ); break;
Mark Wielaard ee9108
             case 0x19: /* FORM_flag_present */break;
Mark Wielaard ee9108
             case 0x20: /* FORM_ref_sig8 */  p += 8; break;
Mark Wielaard ee9108
             case 0x1f20: /* FORM_GNU_ref_alt */ p += ui->dw64 ? 8 : 4; break;
Mark Wielaard ee9108
Index: coregrind/m_debuginfo/readdwarf.c
Mark Wielaard ee9108
===================================================================
Mark Wielaard ee9108
--- valgrind-3.8.0/coregrind/m_debuginfo/readdwarf.c	(revision 12871)
Mark Wielaard ee9108
+++ valgrind-3.8.0/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 ee9108
@@ -1226,9 +1232,9 @@
Mark Wielaard ee9108
       /* Fill ui with offset in .debug_line and compdir */
Mark Wielaard ee9108
       if (0)
Mark Wielaard ee9108
          VG_(printf)( "Reading UnitInfo at 0x%lx.....\n",
Mark Wielaard ee9108
-                      block_img - debug_info_img + 0UL );
Mark Wielaard ee9108
+                      block_img - debug_info_img + 0UL, blklen, blklen_is_64 );
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",