@@ -782,6 +782,15 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
782782 format_values [j ].up_first ;
783783 Dwarf_Unsigned lnform =
784784 format_values [j ].up_second ;
785+ if (line_ptr >= line_ptr_end ) {
786+ free (format_values );
787+ format_values = 0 ;
788+ _dwarf_error_string (dbg , err ,
789+ DW_DLE_LINE_NUMBER_HEADER_ERROR ,
790+ " Running off end of line table"
791+ " reading directory path" );
792+ return DW_DLV_ERROR ;
793+ }
785794 switch (lntype ) {
786795 case DW_LNCT_path : {
787796 char * inc_dir_ptr = 0 ;
@@ -851,6 +860,14 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
851860 _dwarf_error (dbg , err , DW_DLE_ALLOC_FAIL );
852861 return DW_DLV_ERROR ;
853862 }
863+ if (line_ptr >= line_ptr_end ) {
864+ free (filename_entry_pairs );
865+ _dwarf_error_string (dbg , err ,
866+ DW_DLE_LINE_NUMBER_HEADER_ERROR ,
867+ "DW_DLE_LINE_NUMBER_HEADER_ERROR: "
868+ "reading filename format entries" );
869+ return DW_DLV_ERROR ;
870+ }
854871 for (i = 0 ; i < filename_format_count ; i ++ ) {
855872 dres = read_uword_de (& line_ptr ,
856873 & filename_entry_pairs [i ].up_first ,
@@ -900,7 +917,9 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
900917 malloc (sizeof (struct Dwarf_File_Entry_s ));
901918 if (curline == NULL ) {
902919 free (filename_entry_pairs );
903- _dwarf_error (dbg , err , DW_DLE_ALLOC_FAIL );
920+ _dwarf_error_string (dbg , err , DW_DLE_ALLOC_FAIL ,
921+ "DW_DLE_ALLOC_FAIL: "
922+ "Unable to malloc Dwarf_File_Entry_s" );
904923 return DW_DLV_ERROR ;
905924 }
906925 memset (curline ,0 ,sizeof (* curline ));
@@ -1119,6 +1138,15 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
11191138 free (subprog_entry_types );
11201139 return DW_DLV_ERROR ;
11211140 }
1141+ if (line_ptr >= line_ptr_end ) {
1142+ free (subprog_entry_types );
1143+ _dwarf_error_string (dbg , err ,
1144+ DW_DLE_LINE_NUMBER_HEADER_ERROR ,
1145+ "DW_DLE_LINE_NUMBER_HEADER_ERROR: "
1146+ "Line table forms odd, experimental libdwarf" );
1147+ return DW_DLV_ERROR ;
1148+ }
1149+
11221150 subprog_entry_forms = malloc (sizeof (Dwarf_Unsigned ) *
11231151 subprog_format_count );
11241152 if (subprog_entry_forms == NULL ) {
@@ -1193,6 +1221,17 @@ _dwarf_read_line_table_header(Dwarf_Debug dbg,
11931221 for (i = 0 ; i < subprogs_count ; i ++ ) {
11941222 struct Dwarf_Subprog_Entry_s * curline =
11951223 line_context -> lc_subprogs + i ;
1224+ if (line_ptr >= line_ptr_end ) {
1225+ free (subprog_entry_types );
1226+ free (subprog_entry_forms );
1227+ _dwarf_error_string (dbg , err ,
1228+ DW_DLE_LINE_NUMBER_HEADER_ERROR ,
1229+ "DW_DLE_LINE_NUMBER_HEADER_ERROR:"
1230+ " Reading suprogram entry subprogs"
1231+ " in experimental line table"
1232+ " we run off the end of the table" );
1233+ return DW_DLV_ERROR ;
1234+ }
11961235 for (j = 0 ; j < subprog_format_count ; j ++ ) {
11971236 Dwarf_Unsigned lntype =
11981237 subprog_entry_types [j ];
0 commit comments