qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/i386: fix unbounded stack for load_multiboot
@ 2016-03-09  6:14 Peter Xu
  2016-03-09  7:42 ` Fam Zheng
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2016-03-09  6:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, ehabkost, mst, peterx, pbonzini, rth

Use heap rather than stack for kcmdline.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/multiboot.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
index 9e164e6..bc45394 100644
--- a/hw/i386/multiboot.c
+++ b/hw/i386/multiboot.c
@@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg,
     }
 
     /* Commandline support */
-    char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2];
-    snprintf(kcmdline, sizeof(kcmdline), "%s %s",
-             kernel_filename, kernel_cmdline);
+    char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline);
     stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
+    g_free(kcmdline);
 
     stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/i386: fix unbounded stack for load_multiboot
  2016-03-09  6:14 [Qemu-devel] [PATCH] hw/i386: fix unbounded stack for load_multiboot Peter Xu
@ 2016-03-09  7:42 ` Fam Zheng
  2016-03-09  8:27   ` Peter Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Fam Zheng @ 2016-03-09  7:42 UTC (permalink / raw)
  To: Peter Xu; +Cc: peter.maydell, ehabkost, mst, qemu-devel, pbonzini, rth

On Wed, 03/09 14:14, Peter Xu wrote:
> Use heap rather than stack for kcmdline.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  hw/i386/multiboot.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
> index 9e164e6..bc45394 100644
> --- a/hw/i386/multiboot.c
> +++ b/hw/i386/multiboot.c
> @@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg,
>      }
>  
>      /* Commandline support */
> -    char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2];
> -    snprintf(kcmdline, sizeof(kcmdline), "%s %s",
> -             kernel_filename, kernel_cmdline);
> +    char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline);
>      stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
> +    g_free(kcmdline);
>  
>      stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));

While at it, it's better to move the variable declaration to the beginning of
function.

Fam

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/i386: fix unbounded stack for load_multiboot
  2016-03-09  7:42 ` Fam Zheng
@ 2016-03-09  8:27   ` Peter Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Xu @ 2016-03-09  8:27 UTC (permalink / raw)
  To: Fam Zheng; +Cc: peter.maydell, ehabkost, mst, qemu-devel, pbonzini, rth

On Wed, Mar 09, 2016 at 03:42:59PM +0800, Fam Zheng wrote:
> On Wed, 03/09 14:14, Peter Xu wrote:
> > Use heap rather than stack for kcmdline.
> > 
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  hw/i386/multiboot.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
> > index 9e164e6..bc45394 100644
> > --- a/hw/i386/multiboot.c
> > +++ b/hw/i386/multiboot.c
> > @@ -324,10 +324,9 @@ int load_multiboot(FWCfgState *fw_cfg,
> >      }
> >  
> >      /* Commandline support */
> > -    char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2];
> > -    snprintf(kcmdline, sizeof(kcmdline), "%s %s",
> > -             kernel_filename, kernel_cmdline);
> > +    char *kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline);
> >      stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
> > +    g_free(kcmdline);
> >  
> >      stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
> 
> While at it, it's better to move the variable declaration to the beginning of
> function.

Yes, I can do that. Let me post v2.

Thanks.
Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-09  8:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-09  6:14 [Qemu-devel] [PATCH] hw/i386: fix unbounded stack for load_multiboot Peter Xu
2016-03-09  7:42 ` Fam Zheng
2016-03-09  8:27   ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).