Skip to content

Commit 28e5c42

Browse files
author
Egggggg
committed
Change Star::write() to use checked subtractions
1 parent 22066fa commit 28e5c42

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/registers/model_specific.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,16 @@ mod x86_64 {
425425
cs_syscall: SegmentSelector,
426426
ss_syscall: SegmentSelector,
427427
) -> Result<(), &'static str> {
428-
if cs_sysret.0 - 16 != ss_sysret.0 - 8 {
428+
let cs_sysret_cmp = cs_sysret.0.checked_sub(16).ok_or("Sysret CS is not at least 16.")?;
429+
let ss_sysret_cmp = ss_sysret.0.checked_sub(8).ok_or("Sysret SS is not at least 8.")?;
430+
let cs_syscall_cmp = cs_syscall.0;
431+
let ss_syscall_cmp = ss_syscall.0.checked_sub(8).ok_or("Syscall SS is not at least 8.")?;
432+
433+
if cs_sysret_cmp != ss_sysret_cmp {
429434
return Err("Sysret CS and SS is not offset by 8.");
430435
}
431436

432-
if cs_syscall.0 != ss_syscall.0 - 8 {
437+
if cs_syscall_cmp != ss_syscall_cmp {
433438
return Err("Syscall CS and SS is not offset by 8.");
434439
}
435440

0 commit comments

Comments
 (0)