-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
fix for #1055