Skip to content

Commit 2634eff

Browse files
zhengxiaolinXchhagedorn
authored andcommitted
8295646: Ignore zero pairs in address descriptors read by dwarf parser
Reviewed-by: chagedorn
1 parent 50d91a3 commit 2634eff

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Diff for: src/hotspot/share/utilities/elfFile.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ bool DwarfFile::DebugAranges::read_set_header(DebugArangesSetHeader& header) {
763763
return false;
764764
}
765765

766+
_entry_end = _reader.get_position() + header._unit_length;
767+
766768
if (!_reader.read_word(&header._version) || header._version != 2) {
767769
// DWARF 4 uses version 2 as specified in Appendix F of the DWARF 4 spec.
768770
DWARF_LOG_ERROR(".debug_aranges in unsupported DWARF version %" PRIu16, header._version)
@@ -803,7 +805,7 @@ bool DwarfFile::DebugAranges::read_address_descriptors(const DwarfFile::DebugAra
803805
found_matching_set = true;
804806
return true;
805807
}
806-
} while (!is_terminating_entry(descriptor) && _reader.has_bytes_left());
808+
} while (!is_terminating_entry(header, descriptor) && _reader.has_bytes_left());
807809

808810
// Set does not match offset_in_library. Continue with next.
809811
return true;
@@ -819,8 +821,12 @@ bool DwarfFile::DebugAranges::does_match_offset(const uint32_t offset_in_library
819821
&& offset_in_library < descriptor.beginning_address + descriptor.range_length;
820822
}
821823

822-
bool DwarfFile::DebugAranges::is_terminating_entry(const AddressDescriptor& descriptor) {
823-
return descriptor.beginning_address == 0 && descriptor.range_length == 0;
824+
bool DwarfFile::DebugAranges::is_terminating_entry(const DwarfFile::DebugAranges::DebugArangesSetHeader& header,
825+
const AddressDescriptor& descriptor) {
826+
bool is_terminating = _reader.get_position() >= _entry_end;
827+
assert(!is_terminating || (descriptor.beginning_address == 0 && descriptor.range_length == 0),
828+
"a terminating entry needs a pair of zero");
829+
return is_terminating;
824830
}
825831

826832
// Find the .debug_line offset for the line number program by reading from the .debug_abbrev and .debug_info section.

Diff for: src/hotspot/share/utilities/elfFile.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,20 @@ class DwarfFile : public ElfFile {
485485
MarkedDwarfFileReader _reader;
486486
uint32_t _section_start_address;
487487

488+
// a calculated end position
489+
long _entry_end;
490+
488491
bool read_section_header();
489492
bool read_set_header(DebugArangesSetHeader& header);
490493
bool read_address_descriptors(const DwarfFile::DebugAranges::DebugArangesSetHeader& header,
491494
uint32_t offset_in_library, bool& found_matching_set);
492495
bool read_address_descriptor(AddressDescriptor& descriptor);
493496
static bool does_match_offset(uint32_t offset_in_library, const AddressDescriptor& descriptor) ;
494-
static bool is_terminating_entry(const AddressDescriptor& descriptor);
497+
bool is_terminating_entry(const DwarfFile::DebugAranges::DebugArangesSetHeader& header,
498+
const AddressDescriptor& descriptor);
495499
public:
496-
DebugAranges(DwarfFile* dwarf_file) : _dwarf_file(dwarf_file), _reader(dwarf_file->fd()), _section_start_address(0) {}
500+
DebugAranges(DwarfFile* dwarf_file) : _dwarf_file(dwarf_file), _reader(dwarf_file->fd()),
501+
_section_start_address(0), _entry_end(0) {}
497502
bool find_compilation_unit_offset(uint32_t offset_in_library, uint32_t* compilation_unit_offset);
498503

499504
};

0 commit comments

Comments
 (0)