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 e3a0345
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ 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}");
}

#[cfg(feature = "log")]
let mut st0 = registers.st0;
Expand Down Expand Up @@ -439,7 +443,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 +454,13 @@ 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}"
);
}
}
ExecStep::Call(site) => {
#[cfg(feature = "log")]
Expand Down

0 comments on commit e3a0345

Please sign in to comment.