summaryrefslogtreecommitdiff
path: root/hw/i386/multiboot.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2015-01-15 12:26:43 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2015-01-26 12:22:44 +0100
commitb4168498f613db3d908909106146001a9279e732 (patch)
tree09377c746820830afb777e8f8bb2d4856665e0f2 /hw/i386/multiboot.c
parent43bfb507f422a642ea2893555e13ccc2557d810a (diff)
downloadqemu-b4168498f613db3d908909106146001a9279e732.tar.gz
qemu-b4168498f613db3d908909106146001a9279e732.tar.bz2
qemu-b4168498f613db3d908909106146001a9279e732.zip
multiboot: Fix offset of bootloader name
This fixes a bug introduced in commit 5eba5a66 ('Add bootloader name to multiboot implementation'). The calculation of the bootloader name offset didn't consider space occupied by module command lines, so some unlucky module got its command line partially overwritten with a "qemu" string. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/i386/multiboot.c')
-rw-r--r--hw/i386/multiboot.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
index f86d351b3e..1adbe9e25f 100644
--- a/hw/i386/multiboot.c
+++ b/hw/i386/multiboot.c
@@ -156,6 +156,7 @@ int load_multiboot(FWCfgState *fw_cfg,
MultibootState mbs;
uint8_t bootinfo[MBI_SIZE];
uint8_t *mb_bootinfo_data;
+ uint32_t cmdline_len;
/* Ok, let's see if it is a multiboot image.
The header is 12x32bit long, so the latest entry may be 8192 - 48. */
@@ -258,27 +259,28 @@ int load_multiboot(FWCfgState *fw_cfg,
mbs.offset_mbinfo = mbs.mb_buf_size;
/* Calculate space for cmdlines, bootloader name, and mb_mods */
- mbs.mb_buf_size += strlen(kernel_filename) + 1;
- mbs.mb_buf_size += strlen(kernel_cmdline) + 1;
- mbs.mb_buf_size += strlen(bootloader_name) + 1;
+ cmdline_len = strlen(kernel_filename) + 1;
+ cmdline_len += strlen(kernel_cmdline) + 1;
if (initrd_filename) {
const char *r = initrd_filename;
- mbs.mb_buf_size += strlen(r) + 1;
+ cmdline_len += strlen(r) + 1;
mbs.mb_mods_avail = 1;
while (*(r = get_opt_value(NULL, 0, r))) {
mbs.mb_mods_avail++;
r++;
}
- mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail;
}
+ mbs.mb_buf_size += cmdline_len;
+ mbs.mb_buf_size += MB_MOD_SIZE * mbs.mb_mods_avail;
+ mbs.mb_buf_size += strlen(bootloader_name) + 1;
+
mbs.mb_buf_size = TARGET_PAGE_ALIGN(mbs.mb_buf_size);
/* enlarge mb_buf to hold cmdlines, bootloader, mb-info structs */
mbs.mb_buf = g_realloc(mbs.mb_buf, mbs.mb_buf_size);
mbs.offset_cmdlines = mbs.offset_mbinfo + mbs.mb_mods_avail * MB_MOD_SIZE;
- mbs.offset_bootloader = mbs.offset_cmdlines + strlen(kernel_filename) + 1
- + strlen(kernel_cmdline) + 1;
+ mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;
if (initrd_filename) {
char *next_initrd, not_last;