Skip to content

Commit 14d2088

Browse files
committed
FreeBSD: Skip unused ELF section headers
ELF section headers are allowed to be left uninitialized when the section is empty and unused. LLD is a tad more aggressive about this. The ELF reader in the Swift runtime was a bit aggressive about converting the section headers to names and would not skip over these unused sections headers resulting in crashes due to operating on uninitialized memory in the `sh_name` field. This patch teaches the ELF reader to skip over unused section header table entries.
1 parent 705b1a6 commit 14d2088

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ class ReflectionContext
635635
return {nullptr, 0};
636636
// Now for all the sections, find their name.
637637
for (const typename T::Section *Hdr : SecHdrVec) {
638+
// Skip unused headers
639+
if (Hdr->sh_type == llvm::ELF::SHT_NULL)
640+
continue;
638641
uint32_t Offset = Hdr->sh_name;
639642
const char *Start = (const char *)StrTab + Offset;
640643
uint64_t StringSize = strnlen(Start, StrTabSize - Offset);

0 commit comments

Comments
 (0)