Skip to content

Commit e9cb50e

Browse files
committed
[RemoteInspection] Handle special case of large amount of ELF sections.
When parsing ELF, reading the number of sections needs special handling. From the elf man page: If the number of entries in the section header table is larger than or equal to SHN_LORESERVE (0xff00), e_shnum holds the value zero and the real number of entries in the section header table is held in the sh_size member of the initial entry in section header table. Otherwise, the sh_size member of the initial entry in the section header table holds the value zero.
1 parent d3b4817 commit e9cb50e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,26 @@ class ReflectionContext
556556

557557
if (sizeof(typename T::Section) > SectionEntrySize)
558558
return {};
559+
560+
// Special handling for large amount of sections.
561+
// From the elf man page, describing e_shnum:
562+
//
563+
// If the number of entries in the section header table is
564+
// larger than or equal to SHN_LORESERVE (0xff00), e_shnum
565+
// holds the value zero and the real number of entries in the
566+
// section header table is held in the sh_size member of the
567+
// initial entry in section header table. Otherwise, the
568+
// sh_size member of the initial entry in the section header
569+
// table holds the value zero.
570+
if (SectionHdrNumEntries == 0 && SectionEntrySize > 0) {
571+
auto SecBuf = readData(SectionHdrAddress, sizeof(typename T::Section));
572+
if (!SecBuf)
573+
return {};
574+
const typename T::Section *FirstSectHdr =
575+
reinterpret_cast<const typename T::Section *>(SecBuf);
576+
SectionHdrNumEntries = FirstSectHdr->sh_size;
577+
}
578+
559579
if (SectionHdrNumEntries == 0)
560580
return {};
561581

0 commit comments

Comments
 (0)