From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH] tests/qtest/netdev-socket: Avoid variable-length array in inet_get_free_port_multiple()
Date: Thu, 24 Aug 2023 19:03:18 +0200 [thread overview]
Message-ID: <e46d4326-de82-7221-b7f1-cedad7ab7e00@redhat.com> (raw)
In-Reply-To: <20230824164535.2652070-1-peter.maydell@linaro.org>
On 24/08/2023 18.45, Peter Maydell wrote:
> 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>
> ---
> 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 097abc0230b..8eed54801f2 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++) {
Reviewed-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2023-08-24 17:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 16:45 [PATCH] tests/qtest/netdev-socket: Avoid variable-length array in inet_get_free_port_multiple() Peter Maydell
2023-08-24 17:03 ` Thomas Huth [this message]
2023-08-25 4:52 ` Philippe Mathieu-Daudé
2023-08-25 7:02 ` Laurent Vivier
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=e46d4326-de82-7221-b7f1-cedad7ab7e00@redhat.com \
--to=thuth@redhat.com \
--cc=lvivier@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).