multiboot: copy the cmdline verbatim, unescape module strings
PATCH 1/1 multiboot: copy the cmdline verbatim, unescape module strings
get_opt_value() truncates the value at the first comma Rename mb_add_cmdline() to mb_add_modstring() Unescape filename too
Add new mb_add_cmdline() using memcpy()
Signed-off-by Vlad Lungu <[email protected]>
--- hw/i386/multiboot.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
hw/i386/multiboot.c +17 -6
@@ -109,6 +109,16 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; +memcpy (b, cmdline,strlen (cmdline) +1 ); + s->offset_cmdlines +=strlen (b) +1 ; +return s->mb_buf_phys + p; +} + +static uint32_t mb_add_modstring (MultibootState *s,const char *cmdline) +{ +hwaddr p = s->offset_cmdlines; +char *b = (char *)s->mb_buf + p; +get_opt_value (b,strlen (cmdline) +1 , cmdline); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p;
@@ -287,7 +297,7 @@ int load_multiboot(FWCfgState *fw_cfg, mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) { -char *next_initrd, not_last; +char *next_initrd, not_last, tmpbuf[strlen (initrd_filename) +1 ]; mbs.offset_mods = mbs.mb_buf_size;
@@ -301,20 +311,21 @@ int load_multiboot(FWCfgState *fw_cfg, *next_initrd ='\0' ;/* if a space comes after the module filename, treat everything after that as parameters */ -hwaddr c =mb_add_cmdline (&mbs, initrd_filename); +hwaddr c =mb_add_modstring (&mbs, initrd_filename);if ((next_space =strchr (initrd_filename,' ' ))) *next_space ='\0' ; -mb_debug ("multiboot loading module: %s\n" , initrd_filename); - mb_mod_length =get_image_size (initrd_filename); +get_opt_value (tmpbuf,strlen (initrd_filename) +1 , initrd_filename); +mb_debug ("multiboot loading module: %s\n" , tmpbuf); + mb_mod_length =get_image_size (tmpbuf);if (mb_mod_length <0 ) { -fprintf (stderr,"Failed to open file '%s'\n" , initrd_filename); +fprintf (stderr,"Failed to open file '%s'\n" , tmpbuf);exit (1 ); } mbs.mb_buf_size =TARGET_PAGE_ALIGN (mb_mod_length + mbs.mb_buf_size); mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); -load_image (initrd_filename, (unsigned char *)mbs.mb_buf + offs); +load_image (tmpbuf, (unsigned char *)mbs.mb_buf + offs);mb_add_mod (&mbs, mbs.mb_buf_phys + offs, mbs.mb_buf_phys + offs + mb_mod_length, c);
Signature · 1 line
1.9.1
Sorry about replying to myself, I only had one coffee today.
There is no need for mb_add_modstring(), we can simply do get_opt_value(tmpbuf,..) then mb_add_cmdline(&mbs, tmpbuf)
Regards,
Vlad
Quoted 67 lines · Vlad Lungu
get_opt_value()truncates the value at the first comma Renamemb_add_cmdline()tomb_add_modstring()Unescape filename too
Add newmb_add_cmdline()usingmemcpy()Signed-off-by Vlad Lungu <[email protected]>--- hw/i386/multiboot.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)hw/i386/multiboot.c +17
-6@@ -109,6 +109,16 @@ static uint32_t mb_add_cmdline(MultibootState *s, const char *cmdline)hwaddr p = s->offset_cmdlines;char *b = (char *)s->mb_buf + p; +memcpy (b, cmdline,strlen (cmdline) +1 ); + s->offset_cmdlines +=strlen (b) +1 ; +return s->mb_buf_phys + p; +} + +static uint32_t mb_add_modstring (MultibootState *s,const char *cmdline) +{ +hwaddr p = s->offset_cmdlines; +char *b = (char *)s->mb_buf + p; +get_opt_value (b,strlen (cmdline) +1 , cmdline); s->offset_cmdlines +=strlen (b) +1 ;return s->mb_buf_phys + p;@@ -287,7 +297,7 @@ int load_multiboot(FWCfgState *fw_cfg, mbs.offset_bootloader = mbs.offset_cmdlines + cmdline_len;if (initrd_filename) { -char *next_initrd, not_last; +char *next_initrd, not_last, tmpbuf[strlen (initrd_filename) +1 ]; mbs.offset_mods = mbs.mb_buf_size;@@ -301,20 +311,21 @@ int load_multiboot(FWCfgState *fw_cfg, *next_initrd ='\0' ;/* if a space comes after the module filename, treat everything after that as parameters */ -hwaddr c =mb_add_cmdline (&mbs, initrd_filename); +hwaddr c =mb_add_modstring (&mbs, initrd_filename);if ((next_space =strchr (initrd_filename,' ' ))) *next_space ='\0' ; -mb_debug ("multiboot loading module: %s\n" , initrd_filename); - mb_mod_length =get_image_size (initrd_filename); +get_opt_value (tmpbuf,strlen (initrd_filename) +1 , initrd_filename); +mb_debug ("multiboot loading module: %s\n" , tmpbuf); + mb_mod_length =get_image_size (tmpbuf);if (mb_mod_length <0 ) { -fprintf (stderr,"Failed to open file '%s'\n" , initrd_filename); +fprintf (stderr,"Failed to open file '%s'\n" , tmpbuf);exit (1 ); } mbs.mb_buf_size =TARGET_PAGE_ALIGN (mb_mod_length + mbs.mb_buf_size); mbs.mb_buf =g_realloc (mbs.mb_buf, mbs.mb_buf_size); -load_image (initrd_filename, (unsigned char *)mbs.mb_buf + offs); +load_image (tmpbuf, (unsigned char *)mbs.mb_buf + offs);mb_add_mod (&mbs, mbs.mb_buf_phys + offs, mbs.mb_buf_phys + offs + mb_mod_length, c);