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

Fix recursive loop on architectures where flags register is a dynamic value #1065

Merged
merged 4 commits into from
Feb 2, 2024

Conversation

hugsy
Copy link
Owner

@hugsy hugsy commented Jan 30, 2024

Description

Quick fix for a nasty bug I discovered last night:

For (at least) ARM and ARM64$arch.ptrsize is calculated dynamically from CSPR flags, and invokes parse_address. However, parse_address requires ptrsize to be set to determine the alignment.
So we end up in an infinite loop. Which breaks almost everything.

Example on ARM64

↳ File "/home/hugsy/code/gef/gef.py", line 3844, in parse_address()
    →     return to_unsigned_long(gdb.parse_and_eval(address))
↳ File "/home/hugsy/code/gef/gef.py", line 2351, in __get_register_for_selected_frame()
    →     return parse_address(regname)
↳ File "/home/hugsy/code/gef/gef.py", line 2345, in __get_register()
    →     return self.__get_register_for_selected_frame(regname, int(key))
↳ File "/home/hugsy/code/gef/gef.py", line 2363, in register()
    →     return self.__get_register(name)
↳ File "/home/hugsy/code/gef/gef.py", line 2584, in cpsr()
    →     return gef.arch.register(self.flag_register)
↳ File "/home/hugsy/code/gef/gef.py", line 2745, in is_aarch32()
    →     return (self.cpsr & (1 << 4) != 0) and (self.cpsr & (1 << 5) == 0)
↳ File "/home/hugsy/code/gef/gef.py", line 2756, in ptrsize()
    →     if self.is_aarch32():
↳ File "/home/hugsy/code/gef/gef.py", line 3411, in to_unsigned_long()
    →     mask = (1 << (gef.arch.ptrsize*8)) - 1
[...]

Repro: open any binary with gef on arm64, run start

Fix: Simply replacing to_unsigned_long with int is perfectly fine for this situation, which is what the PR does.

Checklist

  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

Copy link

🤖 Coverage update for d7eb298 🔴

Old New
Commit c17a0d2 d7eb298
Score 71.5816% 71.5623% (-0.0193)

Copy link

🤖 Coverage update for f99f8a1 🔴

Old New
Commit c17a0d2 f99f8a1
Score 71.5816% 71.5623% (-0.0193)

Copy link

🤖 Coverage update for f99f8a1 🟢

Old New
Commit c17a0d2 f99f8a1
Score 71.5816% 71.7746% (0.193)

Copy link

github-actions bot commented Feb 2, 2024

🤖 Coverage update for 72541f0 🟢

Old New
Commit c17a0d2 72541f0
Score 71.5872% 71.5872% (0)

Copy link

github-actions bot commented Feb 2, 2024

🤖 Coverage update for 72541f0 🟢

Old New
Commit c17a0d2 72541f0
Score 71.5872% 71.8189% (0.2317)

Copy link

github-actions bot commented Feb 2, 2024

🤖 Coverage update for 37966b1 🟢

Old New
Commit c17a0d2 37966b1
Score 71.5872% 71.7996% (0.2124)

Copy link

github-actions bot commented Feb 2, 2024

🤖 Coverage update for 37966b1 🟢

Old New
Commit c17a0d2 37966b1
Score 71.5872% 71.6065% (0.0193)

@hugsy hugsy merged commit db5b7b8 into main Feb 2, 2024
6 checks passed
@hugsy hugsy deleted the fix_recur_loop_in_arm_mips branch February 2, 2024 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants