aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorZeke Lu <lvzecai@gmail.com>2022-09-15 03:57:43 +0000
committerGopher Robot <gobot@golang.org>2022-09-19 17:01:22 +0000
commitb6d5831caa219aa00574fbacb1026585cf11d6b4 (patch)
tree64489d157800e63223989ee88e956b240d55a7f0 /src/debug
parent73c38f226e15e218411d87a05c878f087ad89455 (diff)
downloadgo-b6d5831caa219aa00574fbacb1026585cf11d6b4.tar.xz
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: aeb70ca8a08e7dbc36ed61bd5a2dabcf432540e9 GitHub-Pull-Request: golang/go#55001 Reviewed-on: https://go-review.googlesource.com/c/go/+/430155 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/elf/file.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go
index f37d4b8e9a..aff2b00aae 100644
--- a/src/debug/elf/file.go
+++ b/src/debug/elf/file.go
@@ -474,7 +474,16 @@ func NewFile(r io.ReaderAt) (*File, error) {
}
// Load section header string table.
- shstrtab, err := f.Sections[shstrndx].Data()
+ if shstrndx == 0 {
+ // If the file has no section name string table,
+ // shstrndx holds the value SHN_UNDEF (0).
+ return f, nil
+ }
+ shstr := f.Sections[shstrndx]
+ if shstr.Type != SHT_STRTAB {
+ return nil, &FormatError{shoff + int64(shstrndx*shentsize), "invalid ELF section name string table type", shstr.Type}
+ }
+ shstrtab, err := shstr.Data()
if err != nil {
return nil, err
}