From patchwork Thu Aug 31 19:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 719020 Delivered-To: patch@linaro.org Received: by 2002:adf:e5c2:0:b0:31d:da82:a3b4 with SMTP id a2csp659597wrn; Thu, 31 Aug 2023 12:18:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEptBbIGnI5DTUNHsnqz4Wd8kAEY+ZRPikutmltwNpD1pFf0A0oEShsi3t5Fs9nWc95syeC X-Received: by 2002:a05:620a:394d:b0:76e:fa49:523e with SMTP id qs13-20020a05620a394d00b0076efa49523emr330968qkn.16.1693509513328; Thu, 31 Aug 2023 12:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693509513; cv=none; d=google.com; s=arc-20160816; b=nm/O2baBRQt4TW0uyPCYqAmuqYqvGRuHImPYgg4eR92N35L3DSWBezc8SDYretJkEQ e30VjExFeR91IRS+0yD/Yv7bKzDcQkQ8xK/WgFjNu5Y4Ujva6GPjSFfxpX9Ilblf/5q2 d5hEtnvAoscJX4SdN4ZiL+Ym1H6fFVoHd3eyyVOgX4lbgiZzD4aJDlerSciW4xrkakJI P+yPWS0xmyduoP+8Hh61HQeAVpv8AOEmvj591uizX5f0Ypyftpcb7VjM44trFfG0Gw8R 8Voyw6Nk36kqxNzZrecgB7x+v6bm0i3AgK7UcqdPLM66ilE6GwkVOX/qlw3xw3z29AgS C67A== 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:cc:to :from:dkim-signature; bh=pTOAPWFYD9cHPnCZknDRCKlTb1DlAq/a97UhZ5O9Xcs=; fh=+Em7evrppgtnW4gsoUbGPJ2NKIk/BhTdmM0YV70IG4A=; b=o+DMS4YDhP7uR8Mfw0TYpSpTATLJjKpiXMoKsKqXz4rDCguyDcTb6BSATFcBNuFkAP 1I3P6bhqM7KVD5bwfM4W7eUSnG5MW+Yvz2xpJB81VPxi/DMk3RoeXSDjF6FAL1vaELl3 1ntVMDzCH1nYz/U/bEs66l53Io9AJjFYKareFWfcowTWFklHEo34ZJYVt4mN5vA/qW0j pAMS+KZ89osJ+MAfKFXbuhD0AF0IUxREGdv9BFVRbYEiHDK7Py28loxH/7az7gp2x7MA Ydq+Y03tSRiOJ5GjmJHbi3RYWhu/43OTvXh0UDnA08B7DYlpj8ikXr/25tE+oNFgUvFr RULw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CBYeHLSN; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ea3-20020a05620a488300b0076d9a4f56casi1422803qkb.167.2023.08.31.12.18.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Aug 2023 12:18:33 -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=@redhat.com header.s=mimecast20190719 header.b=CBYeHLSN; 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=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbnAm-000070-HU; Thu, 31 Aug 2023 15:17:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbnAf-00005j-1A for qemu-devel@nongnu.org; Thu, 31 Aug 2023 15:17:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbnAc-0001xm-TA for qemu-devel@nongnu.org; Thu, 31 Aug 2023 15:17:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693509454; 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=pTOAPWFYD9cHPnCZknDRCKlTb1DlAq/a97UhZ5O9Xcs=; b=CBYeHLSNmHuKbKmGwvmyzEoWDJz37Z9MnuqHBcknhfziqRvfBQM3Hs1jOynVDGtpQAeuiy A1RyMGMaAUuPffLvI4nHnxo+9ABeEkralkeiKJx7zjEQldgal5AirYB/amaBxXd3cVbG1k BQpAEBNcqTZBE18padX/tP1vqVH+clA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-gaal-AmsMjmbgQkDdE_C1w-1; Thu, 31 Aug 2023 15:17:30 -0400 X-MC-Unique: gaal-AmsMjmbgQkDdE_C1w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1CBEA800193; Thu, 31 Aug 2023 19:17:30 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B6A45CC05; Thu, 31 Aug 2023 19:17:28 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Peter Maydell , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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 Message-Id: <20230831191719.140001-5-thuth@redhat.com> In-Reply-To: <20230831191719.140001-1-thuth@redhat.com> References: <20230831191719.140001-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+patch=linaro.org@nongnu.org From: Peter Maydell 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 Message-Id: <20230824164535.2652070-1-peter.maydell@linaro.org> Reviewed-by: Laurent Vivier Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Thomas Huth --- 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++) {