From nobody Mon Feb 9 16:38:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620249116; cv=none; d=zohomail.com; s=zohoarc; b=FnBGgJ0snWcDcOm+d0Z6wn/LLO2WRnc4EBojTQ58vSvF+ciBlUNqHko3ihofjn2EPqYucbV5aQj6fY2Jj443DZHcx0dHyu4FQ/aIxvbMLkMFky4I2QOhf4VZIkcAtwfp8Dnxhr4hZkCt3vRwgAS2bb1XEMmM5rPdQ8J4w4D5gDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620249116; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=tKtzUuVUg3zkWjnpM9cF6E//1jWBtx7/fvE0exQ2eS0=; b=R/7HQCem912SjM+ip7ojM9Cu4o4Gpvrl9TBD4/FP2aXGqiuCgjJzpuYNufw+fLIgbTF4Rvrrg5q0lRLC4X/woxua0ZtyLUJZ8w68V0ZsV7XaPb5TQDTMk4o75YE9hjPOQDSRkB7Wp0USJ6pwPE6lNHmriAaGYqB1KsU78jb0PUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16202491168201006.471285266193; Wed, 5 May 2021 14:11:56 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-112-ek6iS7Y5OueRCtUYdyDlrw-1; Wed, 05 May 2021 17:11:53 -0400 Received: by mail-wm1-f69.google.com with SMTP id b16-20020a7bc2500000b029014587f5376dso1785137wmj.1 for ; Wed, 05 May 2021 14:11:52 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (astrasbourg-653-1-188-220.w90-13.abo.wanadoo.fr. [90.13.127.220]) by smtp.gmail.com with ESMTPSA id c5sm612680wrs.73.2021.05.05.14.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 14:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620249114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tKtzUuVUg3zkWjnpM9cF6E//1jWBtx7/fvE0exQ2eS0=; b=UNLmFJbHNlGR42vDw7CZho5RFiwbk9B66lx+BeZdKCNJZnurvWZJZ9G6An1ukp0Qf9KYAE O3JZCKE3htC3X/9xTa0K9p7P4BBkPobBfGMrslRa89+hHYH/8peq1GZ1cEMVC3MWqK4ar7 9oB/reS/zm1m6o8KPfmcOsN1P0KKxk4= X-MC-Unique: ek6iS7Y5OueRCtUYdyDlrw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tKtzUuVUg3zkWjnpM9cF6E//1jWBtx7/fvE0exQ2eS0=; b=X2aFQ3ocJdYxK8L931MOl4y1+zmjsAXwEB5yjhv5XHk0Pw/usVAJceigPZf+FtdYOe jF8mmLIpuckDLfrjccregWhZt2lV6jl/8ks89r5uWVQnfeai85G1UHhR47cS0VivsI3x Q8mAZYcyfyyTZ2CiWi+Eb1RJwCXxTyeTco2gaH1McPpumyvf3gCn4fEBL1FB0FX4VO+u CYhJEY8nOlJTqtTtqyTSHKW2OAPvDLJO0VAQUh7go3Ji6e7sN5+H9M6/Wh+0bLML7sVq QpN+OnsUW5ClreB0BIyqQam9H5e8EKPaihxttNOJ9h8tYxsFxEOAKTkoWDaR6HueqVi/ ty8g== X-Gm-Message-State: AOAM532fuPE2oEnCpdhvhlVCsCqKJ7j4Gom5H1HuPQyj0B9ZReyik476 74kjikH6q3XEl/90ii0b+n0Bm/ulKAKkx6RHT+Jsgam7yV+/q76n+XY87QfAk6lEy/XPe20sJdW PXFkgNNDT61g3aA== X-Received: by 2002:a05:6000:50d:: with SMTP id a13mr1064634wrf.130.1620249111317; Wed, 05 May 2021 14:11:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyN4fDkR14J/ZumsUGD5UvKJePZJMZ/4JldUq/xifAFnfQpL4iEP4krswocXMfVRV/FONny1A== X-Received: by 2002:a05:6000:50d:: with SMTP id a13mr1064624wrf.130.1620249111193; Wed, 05 May 2021 14:11:51 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-ppc@nongnu.org, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Eduardo Habkost Subject: [PATCH 12/23] hw/i386/multiboot: Avoid dynamic stack allocation Date: Wed, 5 May 2021 23:10:36 +0200 Message-Id: <20210505211047.1496765-13-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210505211047.1496765-1-philmd@redhat.com> References: <20210505211047.1496765-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 Reviewed-by: Richard Henderson --- 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 9e7d69d4705..ccd197603b1 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -161,6 +161,7 @@ int load_multiboot(FWCfgState *fw_cfg, uint8_t *mb_bootinfo_data; uint32_t cmdline_len; GList *mods =3D NULL; + g_autofree char *kcmdline =3D NULL; =20 /* Ok, let's see if it is a multiboot image. The header is 12x32bit long, so the latest entry may be 8192 - 48. = */ @@ -360,9 +361,7 @@ int load_multiboot(FWCfgState *fw_cfg, } =20 /* Commandline support */ - char kcmdline[strlen(kernel_filename) + strlen(kernel_cmdline) + 2]; - snprintf(kcmdline, sizeof(kcmdline), "%s %s", - kernel_filename, kernel_cmdline); + kcmdline =3D g_strdup_printf("%s %s", kernel_filename, kernel_cmdline); stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline)); =20 stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_na= me)); --=20 2.26.3