From patchwork Thu Sep 22 16:35:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 608251 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp504274pvb; Thu, 22 Sep 2022 11:31:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45gX8/012IILSeCJwQGVdiISk4aXJYljDA6tNFQ5oUoFxS6xjZMIPtpAJg5Fr0ExbXbBYe X-Received: by 2002:a05:620a:17aa:b0:6ce:5fe3:1c35 with SMTP id ay42-20020a05620a17aa00b006ce5fe31c35mr3156007qkb.337.1663871491239; Thu, 22 Sep 2022 11:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663871491; cv=none; d=google.com; s=arc-20160816; b=xOV6iTc4hvAcnjk3pqu+3qVngZ9R6FFgSz4WZQYNbJxG53NwLhIKnbcvQ/X2TfYuZl Fbt3mD8x+UXAS+uuty0TDUKTNj/ocT524U776gSm6GX75z/WVaPMXCL1kXgfg2JqiGvk yAM0+QG4NE5nT/EaPsCqf1rTRoN0ozblHEe/gxKaqJ2uFM0TUIklHv+sDVeMAjU9Iqx+ 6cF4gUTpJF7DSMNCvBbHc3Wk5IZN1NMYGXda7KA9jUJ75gT9Gc1NWysF6iG0VR7886AW 5xdzU6UUK6DyuygUxtqEp6n3dkMMHclEJwXguiZRdCU7nyWPcy8oAz1458k9X/sbTHAq /lWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=HVLDjT4fU1zPU/nL/+pXZz3AlOxWu0cbWVrJuViFf8w=; b=zUcSU7kVgP+WXuRG8Pd6b3bvfJhPei+2dNG9QgHx6ryDA0a/leRms8l9V8bWFF97Dz fPAb9eQ6edIH/DMpGiGXg5gG9BkM3PxHaXhdNFPjn1XpeU9mGhv9V5C72q2KwGHZvBhY uwyq+5OzTppdqkYgtmO4wwq4sImlZsEnVVdBvbswpBwW7t+/fOP/22BnoQyzct6GM5l5 03bcel1mczlY/dtTc7188rzI9iRNpdpOuTAh4RtWUtYZSxg7J4n1mS+lw94zJhHQYYoS zw1HySEp/Zp2uku57WyQkgQR9zMW0iUqz+/sfclogED3KQgIu4OufEnHP/Z189/+6qeW qzkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mT1icSoH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bq12-20020a05620a468c00b006ce43e44e79si3254858qkb.7.2022.09.22.11.31.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Sep 2022 11:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mT1icSoH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obQyw-0006GF-PG for patch@linaro.org; Thu, 22 Sep 2022 14:31:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obPBG-0002Df-J0 for qemu-devel@nongnu.org; Thu, 22 Sep 2022 12:36:10 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:40482) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obPB9-0005S9-QH for qemu-devel@nongnu.org; Thu, 22 Sep 2022 12:36:03 -0400 Received: by mail-wr1-x434.google.com with SMTP id x18so10415941wrm.7 for ; Thu, 22 Sep 2022 09:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=HVLDjT4fU1zPU/nL/+pXZz3AlOxWu0cbWVrJuViFf8w=; b=mT1icSoH9npd9mB/Lk4fzf68OXGKXKmlPueey7qtiS5WQ78MmrO5olF5+05uk5z8DH 8ZS2p4pCXssQAOHaM32y45kLZ1vAgX1l3ro1gd3dEdBTfnzhX+QxhslOr/92yX9/zO7Z AuYvIZNrYhJs2Xa3tS/WxnzdbRarYqumuK75hFZO5h+vBTBie77t22FSU9GGIjoaWqzw L9BoVavWbZDR5+GwLzEGKc2BF3BOunH1aJHnaOSoxbqtZsSd/1mPXw5wb4O5HqNOIQ8Q oqcNaobfFyWKjy5SKa7k6SRR4DVGyFUjdTLsrtv+xnrNBpm5nP/GxDNJXLd2aDJlgC1Z bLbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=HVLDjT4fU1zPU/nL/+pXZz3AlOxWu0cbWVrJuViFf8w=; b=o0ZRPIrvJ3tlPmCC+Mqgw49FkjHsOOSle+tG3mRG6L7x8NXTh6lNeSHAwoM/K2sB4e S6dJqFt2aK9yzIJnT6hgycsJ124ht3IzD6m1trUer6hCPNWN7g/htrxu71OOMpSOhAsE JtH0VlyvoA/TWSWHd6CjOFsCigZ41JGtNMmkAnqbJjqlfzEhVWzKVVKcWw7HJBDs+DFn hzxYtopPoJ2QM+uV2vzLkFPnKZfIR4ZDXt4gtl4+9yTjR88TtTtaaIUph620cvr4FciS yLvX0+WX9ziEewzPBuw6MtnUzgMiPbaiUh+2KPxQbVk9h2Vqb6zIgaUQxtuekivxOtgH 1s3Q== X-Gm-Message-State: ACrzQf340BSll2K71/UGbQLlwf08xeBew93Y+xB4lwdmE8MTCeWVeu/Z eL5v5UWr8os2W1HzhjHtaiNgdjh5dN/dHA== X-Received: by 2002:a5d:6088:0:b0:228:e0c5:da5f with SMTP id w8-20020a5d6088000000b00228e0c5da5fmr2549947wrt.221.1663864557290; Thu, 22 Sep 2022 09:35:57 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id iw1-20020a05600c54c100b003b3401f1e24sm6452599wmb.28.2022.09.22.09.35.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 09:35:57 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 29/39] hw/i386/multiboot: Avoid dynamic stack allocation Date: Thu, 22 Sep 2022 17:35:26 +0100 Message-Id: <20220922163536.1096175-30-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220922163536.1096175-1-peter.maydell@linaro.org> References: <20220922163536.1096175-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Use autofree heap allocation instead of variable-length array on the stack. Replace the snprintf() call by g_strdup_printf(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Peter Maydell Message-id: 20220819153931.3147384-9-peter.maydell@linaro.org --- 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 0a10089f14b..963e29362e4 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -163,6 +163,7 @@ int load_multiboot(X86MachineState *x86ms, uint8_t *mb_bootinfo_data; uint32_t cmdline_len; GList *mods = NULL; + g_autofree 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. */ @@ -362,9 +363,7 @@ int load_multiboot(X86MachineState *x86ms, } /* 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)); stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));