From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 8EC2C45D6B;
	Thu, 21 Nov 2024 19:25:56 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 52F95432AC;
	Thu, 21 Nov 2024 19:25:12 +0100 (CET)
Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com
 [209.85.210.175])
 by mails.dpdk.org (Postfix) with ESMTP id 1F2E942FFD
 for <dev@dpdk.org>; Thu, 21 Nov 2024 19:25:03 +0100 (CET)
Received: by mail-pf1-f175.google.com with SMTP id
 d2e1a72fcca58-724a96f188cso1159511b3a.1
 for <dev@dpdk.org>; Thu, 21 Nov 2024 10:25:03 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1732213502;
 x=1732818302; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=tmet1Afzp+Ly93FMmLH+Jw3kE/uX8dEKr+vfzTgvsB8=;
 b=estCbK08f3Ij0JF/UnOS2M28Y+Mm7g2IiXjlIb3UVwqarbPeMpetHXwmqjsJCZswR6
 wS7t92SyqhypVhDJj9jEbAmAdUQw2qwIJD2AvUX+qbMWztgTcm8mgzNWbOV7B8Tn7L9K
 PgxTC+KTmE042dbxxhdNAMzLuqs+Oco+hvOgTyYCL6m9x0PRWw/DqP24+30QgZeO524I
 1i8r9vKw9pryFrs75npQfd03uKJikTuh4h+/yyd8Y4gglb0C/qpIK6cUwA2t7f1ipzMt
 ImfVzU40hpFrKxLF6gJYH9ZvW5UgJ6FuQFIIana7AaTzE/Axflm7/PpiaoV7KOW/6EhA
 7dFw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1732213502; x=1732818302;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=tmet1Afzp+Ly93FMmLH+Jw3kE/uX8dEKr+vfzTgvsB8=;
 b=s4OJQ2MMYkbBgCRKiRxi03HWaQZkSgT+adxcc9C74hs5Sfwuuxio1CwdbeMSnCyTWB
 IJQu2o6S4O/cu0zlesGfkDxyXv5iaUNQeeuiqfU6JGZQeCVJ2fXP8AdHBE0f6deut2Cn
 5rCqVV44aJvXTjKobhigF1YOpYwBRDBCX37Et6ZJQCb+kYYsDXYR8/pyCmzqIVOH/JJg
 3lA+KorNAtGExa2GHunBwPhRCXB3JYWb0/yU7zp8mguz2OBJr4v8SQY60in0LM7cFOwf
 JLrpQhuIAoVYZGMiOHsawuFmoN6ohKNJsn94/1VEe8KiJGfc2ypJwYlkqVNlJFSX3rdj
 zzXg==
X-Gm-Message-State: AOJu0YyUWHRDwJYOko4Su2t4SwAsYv85pCco8HD0PLbbCewV9Yrei5VH
 UTrWWjfjKwrAmNzbp+33V63QA5UtUFEiG4UcWpl5wCYG+HWY7O+eMvBgQVzjv6exDbooziteVm1
 IPWI=
X-Gm-Gg: ASbGnctrR30osW4NlAOsKV4wMdmg6pdqwH4WdThFgxs7fbvoFjV5GWnDoF2tUjM+oXT
 xLkSb4p5gyBm0t7tCl6aCZ5J1B0m/THOSSOG5nGhh8kRiMy7gaRT4yVhmYP0oSy7mAejwcika60
 ELmlKDOwkoGOA9tfRVXXxKco5T0bIuS1o8papKk8L6LrVIAL1MIhFyJGD1njifY+urlBXywKTiQ
 Rmv5aaGBo/VFESTOm416vOhBCiVjD/2HkRnn7Y+hMQT8pm6nUndD0b54OPyxwT0LPi3T3hWVre5
 Ur4rLy3MMFuCdLEit2PXsaXpSpE=
X-Google-Smtp-Source: AGHT+IEDOy4uWn0rPqxWvKT0LWkqpEbGTIfxFwN2BVwHyaHRD3fbsahioQQk7zo8vKoD4+ncYqcXbw==
X-Received: by 2002:a05:6a00:9a0:b0:71e:3b51:e856 with SMTP id
 d2e1a72fcca58-724df3c77a5mr847b3a.1.1732213502223; 
 Thu, 21 Nov 2024 10:25:02 -0800 (PST)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 d2e1a72fcca58-724de454aa1sm70201b3a.4.2024.11.21.10.25.01
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 21 Nov 2024 10:25:01 -0800 (PST)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, getelson@nvidia.com,
 stable@dpdk.org, Bruce Richardson <bruce.richardson@intel.com>,
 Ori Kam <orika@nvidia.com>, Aman Singh <aman.deep.singh@intel.com>
Subject: [PATCH v4 9/9] app/test-pmd: avoid potential outside of array
 reference
Date: Thu, 21 Nov 2024 10:23:30 -0800
Message-ID: <20241121182443.68025-10-stephen@networkplumber.org>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20241121182443.68025-1-stephen@networkplumber.org>
References: <20241114001403.147609-1-stephen@networkplumber.org>
 <20241121182443.68025-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

The order of comparison is wrong, and potentially allows
referencing past the array.

Link: https://pvs-studio.com/en/blog/posts/cpp/1179/

Fixes: 3e3edab530a1 ("ethdev: add flow quota")
Cc: getelson@nvidia.com
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 app/test-pmd/cmdline_flow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 1e4f2ebc55..9e4fc2d95d 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -12892,7 +12892,7 @@ comp_names_to_index(struct context *ctx, const struct token *token,
 	RTE_SET_USED(token);
 	if (!buf)
 		return names_size;
-	if (names[ent] && ent < names_size)
+	if (ent < names_size && names[ent] != NULL)
 		return rte_strscpy(buf, names[ent], size);
 	return -1;
 
-- 
2.45.2