Skip to content

Commit 9cb2bdf

Browse files
committed
lib: halt on impossible jumps
1 parent 1f52ba1 commit 9cb2bdf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/library/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ impl Lib {
385385

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

390395
#[cfg(feature = "log")]
391396
let mut st0 = registers.st0;
@@ -439,7 +444,7 @@ impl Lib {
439444
registers.st0 = false;
440445
assert_eq!(registers.st0, false);
441446
#[cfg(feature = "log")]
442-
eprintln!("execution stopped; {d}st0={z}{r}{}{z}", registers.st0);
447+
eprintln!("halting, {d}st0{z} is set to {r}false{z}");
443448
return None;
444449
}
445450
ExecStep::Next => {
@@ -450,7 +455,14 @@ impl Lib {
450455
ExecStep::Jump(pos) => {
451456
#[cfg(feature = "log")]
452457
eprintln!("{}", pos);
453-
cursor.seek(pos).ok()?;
458+
if cursor.seek(pos).is_err() {
459+
registers.st0 = false;
460+
#[cfg(feature = "log")]
461+
eprintln!(
462+
"jump to non-existing offset; halting, {d}st0{z} is set to {r}false{z}"
463+
);
464+
return None;
465+
}
454466
}
455467
ExecStep::Call(site) => {
456468
#[cfg(feature = "log")]

0 commit comments

Comments
 (0)