Skip to content

Commit

Permalink
11743 installboot: stage2 partition may be smaller than mboot buffer
Browse files Browse the repository at this point in the history
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
tsoome committed Sep 23, 2019
1 parent d8d05a4 commit b97b172
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions usr/src/cmd/boot/installboot/i386/installboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ read_stage2_cb(struct partlist *plist)
uint32_t buf_size;
uint32_t mboot_off;
multiboot_header_t *mboot;
size_t scan_size;

bblock = calloc(1, sizeof (ib_bootblock_t));
if (bblock == NULL)
Expand All @@ -608,8 +609,10 @@ read_stage2_cb(struct partlist *plist)
device = plist->pl_device;
plist->pl_stage = bblock;
offset = device->stage.offset * SECTOR_SIZE;
scan_size = MIN(sizeof (mboot_scan),
(device->stage.size - device->stage.offset) * sector_size);

if (read_in(fd, mboot_scan, sizeof (mboot_scan), offset)
if (read_in(fd, mboot_scan, scan_size, offset)
!= BC_SUCCESS) {
BOOT_DEBUG("Error reading bootblock area\n");
perror("read");
Expand All @@ -618,7 +621,7 @@ read_stage2_cb(struct partlist *plist)
}

/* No multiboot means no chance of knowing bootblock size */
if (find_multiboot(mboot_scan, sizeof (mboot_scan), &mboot_off)
if (find_multiboot(mboot_scan, scan_size, &mboot_off)
!= BC_SUCCESS) {
BOOT_DEBUG("Unable to find multiboot header\n");
(void) close(fd);
Expand Down

0 comments on commit b97b172

Please sign in to comment.