Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tests/qtest/netdev-socket: Avoid variable-length array in inet_get_fr…
…ee_port_multiple()

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>
  • Loading branch information
pm215 authored and huth committed Aug 31, 2023
1 parent 0a1e462 commit b2a7d86
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/qtest/netdev-socket.c
Expand Up @@ -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++) {
Expand Down

0 comments on commit b2a7d86

Please sign in to comment.