From 9cb2bdf4028e67ed093c945b78046b4e3a3dca78 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 19 Oct 2024 01:30:32 +0200 Subject: [PATCH] lib: halt on impossible jumps --- src/library/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/library/lib.rs b/src/library/lib.rs index 9c2b9ca..7c85544 100644 --- a/src/library/lib.rs +++ b/src/library/lib.rs @@ -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; + } #[cfg(feature = "log")] let mut st0 = registers.st0; @@ -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 => { @@ -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; + } } ExecStep::Call(site) => { #[cfg(feature = "log")]