Skip to content

Commit

Permalink
lib: halt on impossible jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 18, 2024
1 parent 1f52ba1 commit 9cb2bdf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ impl Lib {

let mut cursor = Cursor::with(&self.code, &self.data, &self.libs);
let lib_hash = self.id();
cursor.seek(entrypoint).ok()?;
if cursor.seek(entrypoint).is_err() {
registers.st0 = false;
#[cfg(feature = "log")]
eprintln!("jump to non-existing offset; halting, {d}st0{z} is set to {r}false{z}");
return None;

Check warning on line 392 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L389-L392

Added lines #L389 - L392 were not covered by tests
}

#[cfg(feature = "log")]
let mut st0 = registers.st0;
Expand Down Expand Up @@ -439,7 +444,7 @@ impl Lib {
registers.st0 = false;
assert_eq!(registers.st0, false);
#[cfg(feature = "log")]
eprintln!("execution stopped; {d}st0={z}{r}{}{z}", registers.st0);
eprintln!("halting, {d}st0{z} is set to {r}false{z}");
return None;
}
ExecStep::Next => {
Expand All @@ -450,7 +455,14 @@ impl Lib {
ExecStep::Jump(pos) => {
#[cfg(feature = "log")]
eprintln!("{}", pos);
cursor.seek(pos).ok()?;
if cursor.seek(pos).is_err() {
registers.st0 = false;
#[cfg(feature = "log")]
eprintln!(
"jump to non-existing offset; halting, {d}st0{z} is set to {r}false{z}"
);
return None;
}

Check warning on line 465 in src/library/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/library/lib.rs#L458-L465

Added lines #L458 - L465 were not covered by tests
}
ExecStep::Call(site) => {
#[cfg(feature = "log")]
Expand Down

0 comments on commit 9cb2bdf

Please sign in to comment.