Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit eee3878

Browse files
authored
Fix - Interpreter check_pc! (#643)
* Adds test_err_callx_oob_max. * Removes unnecessary debug mode arithmetic guard.
1 parent 410a627 commit eee3878

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/interpreter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ macro_rules! check_pc {
6767
($self:expr, $next_pc:ident, $target_pc:expr) => {
6868
if ($target_pc as usize)
6969
.checked_mul(ebpf::INSN_SIZE)
70-
.and_then(|offset| $self.program.get(offset..offset + ebpf::INSN_SIZE))
70+
.and_then(|offset| {
71+
$self
72+
.program
73+
.get(offset..offset.saturating_add(ebpf::INSN_SIZE))
74+
})
7175
.is_some()
7276
{
7377
$next_pc = $target_pc;

tests/execution.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,20 @@ fn test_err_callx_oob_high() {
24902490
);
24912491
}
24922492

2493+
#[test]
2494+
fn test_err_callx_oob_max() {
2495+
test_interpreter_and_jit_asm!(
2496+
"
2497+
mov64 r0, -0x8
2498+
hor64 r0, -0x1
2499+
callx r0
2500+
exit",
2501+
[],
2502+
TestContextObject::new(3),
2503+
ProgramResult::Err(EbpfError::CallOutsideTextSegment),
2504+
);
2505+
}
2506+
24932507
#[test]
24942508
fn test_callx_unaligned_text_section() {
24952509
test_interpreter_and_jit_elf!(

0 commit comments

Comments
 (0)