From b4fa5b163df118b35a836bbe5706ac268b4cc14b Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Wed, 29 Nov 2023 16:23:18 +0000 Subject: [PATCH] debug/elf: return error in DynValue for invalid dynamic section size This is a follow-up to CL 536400. Fixes #64446 Change-Id: I35646732f62cb1937fd448f94ea518544d4295d4 GitHub-Last-Rev: 55db18a909fd44e6b2f2b98fd1a44ad01bb37932 GitHub-Pull-Request: golang/go#64448 Reviewed-on: https://go-review.googlesource.com/c/go/+/545835 LUCI-TryBot-Result: Go LUCI Run-TryBot: Jes Cok Reviewed-by: Dmitri Shuralyov Reviewed-by: Than McIntosh TryBot-Result: Gopher Robot --- src/debug/elf/file.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index fcbe76b195..7228447c21 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -1656,6 +1656,14 @@ func (f *File) DynValue(tag DynTag) ([]uint64, error) { return nil, err } + dynSize := 8 + if f.Class == ELFCLASS64 { + dynSize = 16 + } + if len(d)%dynSize != 0 { + return nil, errors.New("length of dynamic section is not a multiple of dynamic entry size") + } + // Parse the .dynamic section as a string of bytes. var vals []uint64 for len(d) > 0 { -- 2.50.0