From nobody Thu Nov 28 08:30:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692895557; cv=none; d=zohomail.com; s=zohoarc; b=QCww6jUDsQ2R2HO6fxfqLEQjfBwONBxIzmgaO0LI03qNvA3NKgq8/5Vnmt2v3nk+L8AZhxApvSO/TVonNALZ4M7NH1l5JIixrqAmkAVAQNPsP6qgYTXB69BfG0C8v0PVFCi1goqXaDtwi5ApanF+Z/5PAsTJLHWTeEORZYVhgr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692895557; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=WdhK96lna/G7cRzzC8nsZFsxxJgo7BbHQj8avVRRkf0=; b=LIeE4RZqFKVxl0BUIukrgt18zYzU76xdSMmn7haAeFwOhuBNMSmtKqgVLcjgOBhQekQb/2+CGXnM6qtGkDUcQdPNl3OZYMo+ajZBC0OHrt2lySK6aNg55WdJHmwDvfZIm4t9emBEpuOHausl605irBOwYVUMD1Q1E/qlmPBIaCo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16928955578781004.3900106943879; Thu, 24 Aug 2023 09:45:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZDSp-0000Hi-VJ; Thu, 24 Aug 2023 12:45:43 -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 1qZDSn-0000HA-Lo for qemu-devel@nongnu.org; Thu, 24 Aug 2023 12:45:41 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZDSl-0001U8-HI for qemu-devel@nongnu.org; Thu, 24 Aug 2023 12:45:41 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31c65820134so2226965f8f.1 for ; Thu, 24 Aug 2023 09:45:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id o2-20020adfcf02000000b00317a04131c5sm22630323wrj.57.2023.08.24.09.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 09:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692895537; x=1693500337; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WdhK96lna/G7cRzzC8nsZFsxxJgo7BbHQj8avVRRkf0=; b=ZGrLt+kYuwQHtzOkuejIdc+epTmyExF6J6Gxja2AXm7w54u/qkgCyg+w/1ICqb42PT PlCFJM7LfV0Mwu4kNi3gHc3wSVkE8tyw4z6aNhoFVdBPiYX1K94nyZFhGsJ+3fyVJ8zz +6pRl6i/FALtcxZEXRFFqMFIzX3fZgQYZaqBFD/WZ0Iidnv59wQNLK/CZv8QRcuwmaEL 40QXRtQPRPtGI0yX8gRK3+PyNIto28J8PDOpMm1TLOhb+62ssOtsHpibyhDaRt0XYC6p rZVqbYFsc9hovNzNVCl0HuPsVsbqrbPYK7aFSQW/b3UaOjco1hMSE2yBx0TtB7TSaPRW FoDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692895537; x=1693500337; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WdhK96lna/G7cRzzC8nsZFsxxJgo7BbHQj8avVRRkf0=; b=XfoJnBSqLuuuaInVBo06yROuZ9Oz/CSyFei+6CLWAgTab3pio7ebP+BYfajnyY0UqK ppgMo6ytU1fK7v5Nso7/9pBa7zCGMWeNmDetu5+mgdFi36fLihym9nljyhMzmjwVTRor tPhuypHAYju1xnR6cXytDBnpS8q2cFrJ2jcI+uKc2s/m+zFgKyZKrT37X7+WNGejTKAi 1dWRMu43RPKnjIRmyLrJSZa1G26Qhk+obLiReyU2RAU1GQs5/bmDtbTnEheKV7Ac1a9y GnQB0vYbmF8oQO0PuNORw/GhMDBUqM60n0G5qLI6avQO+HLOXlAVHQqSm/poRzh8uUjI VCJQ== X-Gm-Message-State: AOJu0YzvRpVhiHtPvNHiP1gvgr4yLlZXdG400CU+3u0CA/wD87aM2EBb 5Ys1Ey6App//FqjnD4XimEAaSbUTIr5iq5hasPI= X-Google-Smtp-Source: AGHT+IGF69xRzXYL2ymz8A1VzPtVOkuzdIRlt7FS0IJH2ERj1mtOLSNJ96WlZvVK7L/NAqJvTeMqHQ== X-Received: by 2002:a5d:6703:0:b0:31c:6591:d41e with SMTP id o3-20020a5d6703000000b0031c6591d41emr6188915wru.37.1692895537628; Thu, 24 Aug 2023 09:45:37 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier Subject: [PATCH] tests/qtest/netdev-socket: Avoid variable-length array in inet_get_free_port_multiple() Date: Thu, 24 Aug 2023 17:45:35 +0100 Message-Id: <20230824164535.2652070-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692895558831100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-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 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) =20 static int inet_get_free_port_multiple(int nb, int *port, bool ipv6) { - int sock[nb]; + g_autofree int *sock =3D g_new(int, nb); int i; =20 for (i =3D 0; i < nb; i++) { --=20 2.34.1