qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 4/7] tests/qtest/netdev-socket: Avoid variable-length array in inet_get_free_port_multiple()
Date: Thu, 31 Aug 2023 21:17:16 +0200	[thread overview]
Message-ID: <20230831191719.140001-5-thuth@redhat.com> (raw)
In-Reply-To: <20230831191719.140001-1-thuth@redhat.com>

From: Peter Maydell <peter.maydell@linaro.org>

We use a variable-length array in inet_get_free_port_multiple().
This is only test code called at the start of a test, so switch to a
heap allocation instead.

The codebase has very few VLAs, and if we can get rid of them all we
can make the compiler error on new additions.  This is a defensive
measure against security bugs where an on-stack dynamic allocation
isn't correctly size-checked (e.g.  CVE-2021-3527).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20230824164535.2652070-1-peter.maydell@linaro.org>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/netdev-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
index 097abc0230..8eed54801f 100644
--- a/tests/qtest/netdev-socket.c
+++ b/tests/qtest/netdev-socket.c
@@ -82,7 +82,7 @@ static int inet_get_free_port_socket_ipv6(int sock)
 
 static int inet_get_free_port_multiple(int nb, int *port, bool ipv6)
 {
-    int sock[nb];
+    g_autofree int *sock = g_new(int, nb);
     int i;
 
     for (i = 0; i < nb; i++) {
-- 
2.39.3



  parent reply	other threads:[~2023-08-31 19:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 19:17 [PULL 0/7] s390x and qtest patches Thomas Huth
2023-08-31 19:17 ` [PULL 1/7] target/s390x: Define TARGET_HAS_PRECISE_SMC Thomas Huth
2023-08-31 19:17 ` [PULL 2/7] tests/tcg/s390x: Test precise self-modifying code handling Thomas Huth
2023-08-31 19:17 ` [PULL 3/7] tests/qtest/usb-hcd-xhci-test: Check availability of devices before using them Thomas Huth
2023-08-31 19:17 ` Thomas Huth [this message]
2023-08-31 19:17 ` [PULL 5/7] tests/qtest/bios-tables-test: Check for virtio-iommu device before using it Thomas Huth
2023-08-31 19:17 ` [PULL 6/7] subprojects/berkeley-testfloat-3: Update to fix a problem with compiler warnings Thomas Huth
2023-08-31 19:17 ` [PULL 7/7] meson: test for CONFIG_TCG in config_all Thomas Huth
2023-09-05 15:08 ` [PULL 0/7] s390x and qtest patches Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230831191719.140001-5-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).