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

reassembler: Fix addition type error in address calculation #4443

Merged
merged 1 commit into from Feb 7, 2024

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Feb 3, 2024

When an instruction contains an operand that is neither a memory nor an immediate operand (e.g. a floating-point operand) then operand_offset is set to None:

operand_offsets = []
for operand in capstone_instr.operands:
if operand.type == capstone.CS_OP_IMM:
operand_offsets.append(capstone_instr.imm_offset)
elif operand.type == capstone.CS_OP_MEM:
operand_offsets.append(capstone_instr.disp_offset)
else:
operand_offsets.append(None)

This causes a type error when calculating the address in register_instruction_reference:

addr = insn_addr + operand_offset

I ran into this issue while packaging angr for Guix where test_ln_gcc_O2 fails because of this:

self = <Reassembler Analysis Result at 0x7fffe4c63190>, insn_addr = 4201104
ref_addr = 6344696, sort = 'absolute', operand_offset = None

    def register_instruction_reference(self, insn_addr, ref_addr, sort, operand_offset):
	if not self.log_relocations:
	    return

>       addr = insn_addr + operand_offset
E       TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

It seems to me that this regression was introduced in #1739, it is presently unclear to me why this doesn't fail on the CI. Looking at the aforementioned pull request, it seems to me that it was intended to use a zero offset for these instructions. This commit changes the implementation accordingly, thereby fixing the aforementioned test failure for me.

When an instruction contains an operand that is neither a memory
nor an immediate operand (e.g. a floating-point operand) then
`operand_offset` is set to `None`. This causes a type error when
calculating the address in `register_instruction_reference`:

https://github.com/angr/angr/blob/b0d099550163ca56424994c8ee80b8cacec6490c/angr/analyses/reassembler.py#L1980

I ran into this issue while packaging angr for Guix where the
`test_ln_gcc_O2` test case fails (due to this issue) with the
following error message:

	self = <Reassembler Analysis Result at 0x7fffe4c63190>, insn_addr = 4201104
	ref_addr = 6344696, sort = 'absolute', operand_offset = None

	    def register_instruction_reference(self, insn_addr, ref_addr, sort, operand_offset):
		if not self.log_relocations:
		    return

	>       addr = insn_addr + operand_offset
	E       TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

It seems to me that this regression was introduced in angr#1739, it is
presently unclear to me why this doesn't fail on the CI.
@ltfish ltfish self-assigned this Feb 6, 2024
@ltfish ltfish added the bug Something is broken label Feb 6, 2024
@ltfish ltfish merged commit 6b9bf76 into angr:master Feb 7, 2024
17 of 18 checks passed
@ltfish
Copy link
Member

ltfish commented Feb 7, 2024

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants