]> Cypherpunks.ru repositories - gostls13.git/commitdiff
debug/elf: validate offset and file size ranges
authorDan Kortschak <dan@kortschak.io>
Sat, 27 Aug 2022 03:25:43 +0000 (12:55 +0930)
committerGopher Robot <gobot@golang.org>
Mon, 29 Aug 2022 20:04:56 +0000 (20:04 +0000)
Change-Id: Iebe31b91c6e81438120f50a8089a8efca3d5339d
Reviewed-on: https://go-review.googlesource.com/c/go/+/426115
Run-TryBot: Dan Kortschak <dan@kortschak.io>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/debug/elf/file.go

index 95c28c143349f647d4ea5b765b9c0bc0460e175b..f37d4b8e9add355f4cd896565459854312842c11 100644 (file)
@@ -377,6 +377,12 @@ func NewFile(r io.ReaderAt) (*File, error) {
                                Align:  ph.Align,
                        }
                }
+               if int64(p.Off) < 0 {
+                       return nil, &FormatError{off, "invalid program header offset", p.Off}
+               }
+               if int64(p.Filesz) < 0 {
+                       return nil, &FormatError{off, "invalid program header file size", p.Filesz}
+               }
                p.sr = io.NewSectionReader(r, int64(p.Off), int64(p.Filesz))
                p.ReaderAt = p.sr
                f.Progs[i] = p