Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/proc: pad variable mem in extractVarInfoFromEntry #3365

Merged
merged 2 commits into from May 15, 2023

Conversation

ZekeLu
Copy link
Contributor

@ZekeLu ZekeLu commented May 11, 2023

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.

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 go-delve#3364.
@@ -1207,6 +1207,11 @@ func extractVarInfoFromEntry(tgt *Target, bi *BinaryInfo, image *Image, regs op.
}
}
if cmem != nil {
paddingBytes := int(t.Common().ByteSize) - len(cmem.data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved inside newCompositeMemory in pkg/proc/mem.go (add an extra size int parameter to it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Alessandro! I have moved the padding logic to newCompositeMemory. Since the type of CommonType.ByteSize is int64, I add the extra parameter as size int64. Please take another look.

@aarzilli
Copy link
Member

LGTM, thank you!

@ZekeLu
Copy link
Contributor Author

ZekeLu commented May 13, 2023

Thank you! Should I do a force push to squash the two commits into one?

@aarzilli
Copy link
Member

No need.

Copy link
Member

@derekparker derekparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekparker derekparker merged commit 463b97d into go-delve:master May 15, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg/proc: failed to call method on struct type: write out of bounds
3 participants