From patchwork Thu Aug 24 16:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 716564 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp1446033wrp; Thu, 24 Aug 2023 09:45:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFy4nB4M2sqSKFckBUvjzyEHE/f9txHB6daSJlclwhfu+48HnJ2njifixDQ5a+PTswqQP4z X-Received: by 2002:a05:622a:1182:b0:410:9855:aae with SMTP id m2-20020a05622a118200b0041098550aaemr13865954qtk.19.1692895557008; Thu, 24 Aug 2023 09:45:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692895556; cv=none; d=google.com; s=arc-20160816; b=oIC2LjeWHBHoeA35WqH9LQ5qmPkfDRKW7bSF/TadqfPVA6aE56VZxdWLn6JUU8CS51 sMbT93HHd72CypxCU2Q+i3O3ULglWVod+zhsZekG88kcDQpykYAAIjrYdyWGSklGUa1N SAXZg1Btczv2Q3Ry0m535tTetqeW3UD9EgHD88UTox1uCcl6rE8r0J7WyCpx60VwLRwW hQx2Vk0Bj1a/JXU+P24gbKsouaj0PKK3c+86oUgvGh368yMi4EIlMMScvcmErA2zAGXP R0jgNk7Yvucx0jVg961G62E1BOI8rf3R70zkZVqqORfNNfdPnJalisz+P9HteW/iF1+p nrTA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=WdhK96lna/G7cRzzC8nsZFsxxJgo7BbHQj8avVRRkf0=; fh=H4RPQ+DwuXnGqTnLEzndMn7p3gnvvN4oXHLNNkTqsMQ=; b=SbsdRv0pq5yFAGqeWP/lfffk6iUrVUvVE3IeOYECx71dfIHs4EJJYnF2TRNkAG1mh0 WQTSfxkq2F/vgPJLdGMxwDsmZpqRhNYXWPZCOdSbmHNdu561Q2O91vqh2DhgET6I5C1g 18YyBXg+45KATjHa4/JxTy7JI1TF75hX0S0idmKJJ1H7OGrp13IZTcmH01tyXwc4NlW2 b1kEY/I/MJOsVnxNbCMX3n3SXDhCtb/FLvsYg07vXSbV5xaRHmOUMftvAL8xz0qmc7wO fbnBkcRxyN9Jms2kLYE9Kthh5jkJRMcq+eBjQWklNvCG6oKbHuGrIwJqjcUeeH/TFEnE S6eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZGrLt+kY; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o19-20020a05622a139300b0040f07863f74si4675330qtk.252.2023.08.24.09.45.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Aug 2023 09:45:56 -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=@linaro.org header.s=google header.b=ZGrLt+kY; 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=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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 Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier --- 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++) {