mirror of https://github.com/ipxe/ipxe.git
[hdprefix] Avoid attempts to read beyond the end of the disk
When booting from a hard disk image (e.g. bin/ipxe.usb) within an emulator such as QEMU, the disk may not exist beyond the end of the image. Limit all reads to the length of the image to avoid spurious errors when loading the iPXE image. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/64/head
parent
1fdf4dddbd
commit
84e25513b1
|
@ -27,14 +27,18 @@ load_image:
|
||||||
popw %es
|
popw %es
|
||||||
popal
|
popal
|
||||||
|
|
||||||
1: /* Read to end of current track */
|
1: /* Read to end of current track (or end of image) */
|
||||||
movb %cl, %al
|
movb %cl, %al
|
||||||
negb %al
|
negb %al
|
||||||
addb max_sector, %al
|
addb max_sector, %al
|
||||||
incb %al
|
incb %al
|
||||||
andb $0x3f, %al
|
andb $0x3f, %al
|
||||||
movzbl %al, %eax
|
movzbl %al, %eax
|
||||||
call *read_sectors
|
movl load_length, %ebx
|
||||||
|
cmpl %eax, %ebx
|
||||||
|
ja 2f
|
||||||
|
movl %ebx, %eax
|
||||||
|
2: call *read_sectors
|
||||||
jc load_failed
|
jc load_failed
|
||||||
|
|
||||||
/* Update %es */
|
/* Update %es */
|
||||||
|
@ -53,12 +57,12 @@ load_image:
|
||||||
orb $0x01, %cl
|
orb $0x01, %cl
|
||||||
incb %dh
|
incb %dh
|
||||||
cmpb max_head, %dh
|
cmpb max_head, %dh
|
||||||
jbe 2f
|
jbe 3f
|
||||||
xorb %dh, %dh
|
xorb %dh, %dh
|
||||||
incb %ch
|
incb %ch
|
||||||
jnc 2f
|
jnc 3f
|
||||||
addb $0xc0, %cl
|
addb $0xc0, %cl
|
||||||
2:
|
3:
|
||||||
/* Loop until whole image is read */
|
/* Loop until whole image is read */
|
||||||
subl %eax, load_length
|
subl %eax, load_length
|
||||||
ja 1b
|
ja 1b
|
||||||
|
|
Loading…
Reference in New Issue