pkg/proc: pad variable mem in extractVarInfoFromEntry (#3365)

* pkg/proc: pad variable mem in extractVarInfoFromEntry

On 64 bit system, the byte size of the following struct is 16:
    type myStruct struct {
       a int
       b uint32
    }
But extractVarInfoFromEntry only allocates a mem of 12 bytes for it.
When calling method of this struct with the "call" command, it will
result in this error:
    write out of bounds

This patch extends the mem by adding padding bytes to the end of the
mem.

Fixes #3364.

* move the padding logic into newCompositeMemory
This commit is contained in:
Zeke Lu
2023-05-16 05:46:33 +08:00
committed by GitHub
parent 1c9792bce4
commit 463b97dd36
6 changed files with 29 additions and 10 deletions

View File

@ -1198,9 +1198,9 @@ func extractVarInfoFromEntry(tgt *Target, bi *BinaryInfo, image *Image, regs op.
if pieces != nil {
var cmem *compositeMemory
if tgt != nil {
addr, cmem, err = tgt.newCompositeMemory(mem, regs, pieces, descr)
addr, cmem, err = tgt.newCompositeMemory(mem, regs, pieces, descr, t.Common().ByteSize)
} else {
cmem, err = newCompositeMemory(mem, bi.Arch, regs, pieces)
cmem, err = newCompositeMemory(mem, bi.Arch, regs, pieces, t.Common().ByteSize)
if cmem != nil {
cmem.base = fakeAddressUnresolv
addr = int64(cmem.base)