chain.c32: error out on missing boot sector signature
authorH. Peter Anvin <hpa@zytor.com>
Thu, 31 Jul 2008 02:22:07 +0000 (19:22 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 31 Jul 2008 02:22:07 +0000 (19:22 -0700)
If we're booting a disk or partition, then error out if the loaded
sector doesn't have a boot sector signature, rather than the
otherwise-inevitable crash.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/modules/chain.c

index 2f79aaf..979ede2 100644 (file)
@@ -814,6 +814,13 @@ int main(int argc, char *argv[])
     }
   }
 
+  if (!opt.loadfile) {
+    if (*(uint16_t *)((char *)boot_sector+boot_size-2) != 0xaa55) {
+      error("Boot sector signature not found (unbootable disk/partition?)\n");
+      goto bail;
+    }
+  }
+
   if (partinfo) {
     /* 0x7BE is the canonical place for the first partition entry. */
     regs.esi.w[0] = 0x7be;