Skip to content

Commit b6d5831

Browse files
ZekeLugopherbot
authored andcommitted
debug/elf: validate shstrndx
Changes: 1. When e_shstrndx holds the value SHN_UNDEF (0), the file has no section name string table. In this case, do not try to set section names . 2. e_shstrndx should point to an SHT_STRTAB section. If it does not, returns an error. Reference: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html Updates #54967. Change-Id: Ic8f228061d996fd7845dfa630719a1ba12d2bb60 GitHub-Last-Rev: aeb70ca GitHub-Pull-Request: #55001 Reviewed-on: https://go-review.googlesource.com/c/go/+/430155 Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 73c38f2 commit b6d5831

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/debug/elf/file.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,16 @@ func NewFile(r io.ReaderAt) (*File, error) {
474474
}
475475

476476
// Load section header string table.
477-
shstrtab, err := f.Sections[shstrndx].Data()
477+
if shstrndx == 0 {
478+
// If the file has no section name string table,
479+
// shstrndx holds the value SHN_UNDEF (0).
480+
return f, nil
481+
}
482+
shstr := f.Sections[shstrndx]
483+
if shstr.Type != SHT_STRTAB {
484+
return nil, &FormatError{shoff + int64(shstrndx*shentsize), "invalid ELF section name string table type", shstr.Type}
485+
}
486+
shstrtab, err := shstr.Data()
478487
if err != nil {
479488
return nil, err
480489
}

0 commit comments

Comments
 (0)