From patchwork Wed Mar 9 08:30:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 594882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BD6751402A1 for ; Wed, 9 Mar 2016 19:30:58 +1100 (AEDT) Received: from localhost ([::1]:39883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adZWC-0001ut-SE for incoming@patchwork.ozlabs.org; Wed, 09 Mar 2016 03:30:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adZVq-0001d2-31 for qemu-devel@nongnu.org; Wed, 09 Mar 2016 03:30:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adZVk-0006Aj-Sm for qemu-devel@nongnu.org; Wed, 09 Mar 2016 03:30:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48483) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adZVk-0006AX-Nz for qemu-devel@nongnu.org; Wed, 09 Mar 2016 03:30:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 02A6E7822F; Wed, 9 Mar 2016 08:30:27 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-238.nay.redhat.com [10.66.14.238]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u298UIAj024293; Wed, 9 Mar 2016 03:30:20 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 9 Mar 2016 16:30:10 +0800 Message-Id: <1457512210-2835-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, famz@redhat.com, ehabkost@redhat.com, mst@redhat.com, peterx@redhat.com, pbonzini@redhat.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH v2] hw/i386: fix unbounded stack for load_multiboot X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use heap rather than stack for kcmdline. Signed-off-by: Peter Xu Reviewed-by: Eduardo Habkost --- hw/i386/multiboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index 9e164e6..ddc3780 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -158,6 +158,7 @@ int load_multiboot(FWCfgState *fw_cfg, uint8_t bootinfo[MBI_SIZE]; uint8_t *mb_bootinfo_data; uint32_t cmdline_len; + char *kcmdline = NULL; /* Ok, let's see if it is a multiboot image. The header is 12x32bit long, so the latest entry may be 8192 - 48. */ @@ -324,10 +325,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); + 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));