diff --git a/src/debug/buildinfo/buildinfo.go b/src/debug/buildinfo/buildinfo.go index 8bc5753a2d71ce..a7019a666e2aa4 100644 --- a/src/debug/buildinfo/buildinfo.go +++ b/src/debug/buildinfo/buildinfo.go @@ -19,6 +19,7 @@ import ( "encoding/binary" "errors" "fmt" + "internal/saferio" "internal/xcoff" "io" "io/fs" @@ -260,12 +261,7 @@ func (x *elfExe) ReadData(addr, size uint64) ([]byte, error) { if n > size { n = size } - data := make([]byte, n) - _, err := prog.ReadAt(data, int64(addr-prog.Vaddr)) - if err != nil { - return nil, err - } - return data, nil + return saferio.ReadDataAt(prog, n, int64(addr-prog.Vaddr)) } } return nil, errUnrecognizedFormat @@ -308,12 +304,7 @@ func (x *peExe) ReadData(addr, size uint64) ([]byte, error) { if n > size { n = size } - data := make([]byte, n) - _, err := sect.ReadAt(data, int64(addr-uint64(sect.VirtualAddress))) - if err != nil { - return nil, errUnrecognizedFormat - } - return data, nil + return saferio.ReadDataAt(sect, n, int64(addr-uint64(sect.VirtualAddress))) } } return nil, errUnrecognizedFormat @@ -360,12 +351,7 @@ func (x *machoExe) ReadData(addr, size uint64) ([]byte, error) { if n > size { n = size } - data := make([]byte, n) - _, err := seg.ReadAt(data, int64(addr-seg.Addr)) - if err != nil { - return nil, err - } - return data, nil + return saferio.ReadDataAt(seg, n, int64(addr-seg.Addr)) } } return nil, errUnrecognizedFormat @@ -401,12 +387,7 @@ func (x *xcoffExe) ReadData(addr, size uint64) ([]byte, error) { if n > size { n = size } - data := make([]byte, n) - _, err := sect.ReadAt(data, int64(addr-sect.VirtualAddress)) - if err != nil { - return nil, err - } - return data, nil + return saferio.ReadDataAt(sect, n, int64(addr-sect.VirtualAddress)) } } return nil, errors.New("address not mapped") @@ -438,12 +419,7 @@ func (x *plan9objExe) ReadData(addr, size uint64) ([]byte, error) { if n > size { n = size } - data := make([]byte, n) - _, err := sect.ReadAt(data, int64(addr-uint64(sect.Offset))) - if err != nil { - return nil, err - } - return data, nil + return saferio.ReadDataAt(sect, n, int64(addr-uint64(sect.Offset))) } } return nil, errors.New("address not mapped")