+
Skip to content

read/cfi: check for overflow when evaluating DW_CFA_advance_loc #730

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

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,13 @@ where
}
AdvanceLoc { delta } => {
let delta = Wrapping(u64::from(delta)) * self.code_alignment_factor;
self.next_start_address = (Wrapping(self.ctx.start_address()) + delta).0;
let address = self
.ctx
.start_address()
.checked_add(delta.0)
.ok_or(Error::AddressOverflow)?;

self.next_start_address = address;
self.ctx.row_mut().end_address = self.next_start_address;
return Ok(true);
}
Expand Down Expand Up @@ -5481,9 +5487,11 @@ mod tests {
let cie = make_test_cie();
let mut ctx = UnwindContext::new();
ctx.row_mut().start_address = u64::MAX;
let mut expected = ctx.clone();
expected.row_mut().end_address = 42 * cie.code_alignment_factor - 1;
let instructions = [(Ok(true), CallFrameInstruction::AdvanceLoc { delta: 42 })];
let expected = ctx.clone();
let instructions = [(
Err(Error::AddressOverflow),
CallFrameInstruction::AdvanceLoc { delta: 42 },
)];
assert_eval(ctx, expected, cie, None, instructions);
}

Expand Down
6 changes: 6 additions & 0 deletions src/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ pub enum Error {
UnknownCallFrameInstruction(constants::DwCfa),
/// The end of an address range was before the beginning.
InvalidAddressRange,
/// An address calculation overflowed.
///
/// This is returned in cases where the address is expected to be
/// larger than a previous address, but the calculation overflowed.
AddressOverflow,
/// Encountered a call frame instruction in a context in which it is not
/// valid.
CfiInstructionInInvalidContext,
Expand Down Expand Up @@ -543,6 +548,7 @@ impl Error {
Error::InvalidAddressRange => {
"The end of an address range must not be before the beginning."
}
Error::AddressOverflow => "An address calculation overflowed.",
Error::CfiInstructionInInvalidContext => {
"Encountered a call frame instruction in a context in which it is not valid."
}
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载