Skip to content

Commit fbd8759

Browse files
committed
[Backtracing][Linux] Ignore SHT_NULL sections.
The ELF specification says that if a section's type is set to `SHT_NULL`, _none_ of the other fields are valid, so we shouldn't even be trying to read the section name. (We won't crash, because of how all of this code works, but we might read an incorrect name.) rdar://154837649
1 parent ef934e0 commit fbd8759

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/RuntimeModule/Elf.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,11 @@ final class ElfImage<SomeElfTraits: ElfTraits>
14631463
let stringSect = ElfStringSection(source: stringSource)
14641464

14651465
for shdr in sectionHeaders {
1466+
// All other fields are undefined for SHT_NULL
1467+
if shdr.sh_type == .SHT_NULL {
1468+
continue
1469+
}
1470+
14661471
guard let name = stringSect.getStringAt(index: Int(shdr.sh_name)) else {
14671472
continue
14681473
}
@@ -1600,6 +1605,11 @@ final class ElfImage<SomeElfTraits: ElfTraits>
16001605
let stringSect = ElfStringSection(source: stringSource)
16011606

16021607
for shdr in sectionHeaders {
1608+
// All other fields are undefined for SHT_NULL
1609+
if shdr.sh_type == .SHT_NULL {
1610+
continue
1611+
}
1612+
16031613
guard let sname
16041614
= stringSect.getStringAt(index: Int(shdr.sh_name)) else {
16051615
continue

0 commit comments

Comments
 (0)