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

Merged
merged 10 commits into from
Sep 29, 2024
18 changes: 16 additions & 2 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -10737,8 +10737,22 @@ def read_cstring(self,
try:
res_bytes = self.read(address, length)
except gdb.error:
err(f"Can't read memory at '{address}'")
return ""
current_address = address
res_bytes = b""
while len(res_bytes) < length:
try:
new_end_addr = current_address + DEFAULT_PAGE_SIZE
ValekoZ marked this conversation as resolved.
Show resolved Hide resolved
page_mask = ~(DEFAULT_PAGE_SIZE - 1)
size = (new_end_addr & page_mask) - current_address
ValekoZ marked this conversation as resolved.
Show resolved Hide resolved

res_bytes += self.read(current_address, size)

current_address += size
except:
ValekoZ marked this conversation as resolved.
Show resolved Hide resolved
if not res_bytes:
err(f"Can't read memory at '{address}'")
ValekoZ marked this conversation as resolved.
Show resolved Hide resolved
return ""
break
try:
with warnings.catch_warnings():
# ignore DeprecationWarnings (see #735)
Expand Down
Loading