[syslinux] [PATCH v2] core/diskboot.inc: adjust handover DS:SI check

Michal Soltys soltys at ziu.info
Mon Feb 21 01:04:34 PST 2011


- we can't simply shift SI, as it might be not divisible by 16
- we have to make sure, whole 76 bytes of copied area doesn't
  overlap

Currently, the checks guarantee that:

DS:SI doesn't overflow
DS:SI >= 1024
DS:SI <= PartInfo - 76

Signed-off-by: Michal Soltys <soltys at ziu.info>
---
 core/diskboot.inc |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/core/diskboot.inc b/core/diskboot.inc
index 1be6ade..fd97443 100644
--- a/core/diskboot.inc
+++ b/core/diskboot.inc
@@ -182,13 +182,15 @@ floppy:
 harddisk:
 		mov dx,[di-76-10]	; Original DS
 		mov si,[di-76-12]	; Original SI
-		shr si,4
-		jz .no_partition	; SI == 0 -> assume no partition
+		test dh,0f0h
+		jnz .no_partition	; shl would overflow
+		shl dx,4
 		add dx,si
-		cmp dx,1024 >> 4	; DS:SI < 1K (inside the IVT)?
+		jc .no_partition	; overflow, DS:SI must be less than 64 KiB
+		cmp dx,1024		; DS:SI < 1 KiB (inside the IVT) ?
 		jb .no_partition
-		cmp dx,PartInfo >> 4	; DS:SI in overwritten memory?
-		jae .no_partition
+		cmp dx, PartInfo-76
+		ja .no_partition	; copied area (76 bytes) overlaps with PartInfo
 		test byte [di-76],7Fh	; Sanity check: "active flag" should
 		jnz .no_partition	; be 00 or 80
 		cmp [di-76+4],cl	; Sanity check: partition type != 0
-- 
1.7.2.1




More information about the Syslinux mailing list