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

[memory] Fix read_cstring trying to read too far #1112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ValekoZ
Copy link
Collaborator

@ValekoZ ValekoZ commented May 29, 2024

fix for #1055

Copy link

🤖 Coverage update for 36898ce 🔴

Old New
Commit 757f5bb 36898ce
Score 71.5302% 71.4923% (-0.0379)

Copy link

🤖 Coverage update for e057b6d 🔴

Old New
Commit 757f5bb e057b6d
Score 71.5302% 71.4923% (-0.0379)

gef.py Show resolved Hide resolved
@ValekoZ ValekoZ added this to the next milestone Jun 3, 2024
Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

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

I think this approach is not very optimal. I suggested several options but feel free to bring others as long as they don't impact the perf as much.

Also this needs to be tested.

@@ -10597,10 +10597,34 @@ def read_cstring(self,
encoding = encoding or "unicode-escape"
length = min(address | (DEFAULT_PAGE_SIZE-1), max_length+1)

while not self.get_section(address + length - 1) and length > 0:
Copy link
Owner

Choose a reason for hiding this comment

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

I didn't measure it but I think this approach may cause a slow down in read_cstring for long printable strings. I also find quite complex for what is actually intended to do because you'll be impacting all cases of use of this function for only a minority of cases that violate page boundary.

A simpler approach would be to remove all this, simply let self.read execute: if a gdb.MemoryError, use the exception information calculate the maximum valid length and re-read.

Another approach would be to check early on when setting length that address + length is a readable address.

@ValekoZ ValekoZ requested a review from hugsy June 25, 2024 14:18
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.

None yet

3 participants