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 B834645CFB;
	Thu, 14 Nov 2024 01:15:03 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id A9761427B0;
	Thu, 14 Nov 2024 01:14:28 +0100 (CET)
Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com
 [209.85.210.181])
 by mails.dpdk.org (Postfix) with ESMTP id 96A9642790
 for <dev@dpdk.org>; Thu, 14 Nov 2024 01:14:24 +0100 (CET)
Received: by mail-pf1-f181.google.com with SMTP id
 d2e1a72fcca58-71e79f73aaeso6247525b3a.3
 for <dev@dpdk.org>; Wed, 13 Nov 2024 16:14:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1731543264;
 x=1732148064; 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=JmjyeJ3NyJzEDSb/rKGkJOOeIRgISsKBzXSi7SCrSRY=;
 b=mEKr2qoNK/I7r2qLz5MGqvh9lOtjZgd100zI37x6mU88d4+iHzw/ZrGrdqm5o4Qv4M
 mlkMNXthTOnYWuyjKISUv4PKDtMNCdk8Bpfsnvelq9N0RsWq5M5H0tK2Df5XSJlhv9hK
 byxLzSZpqzoZJg+gh/SQXvRjnOF8ZNzehDK5UfAYZGraFQzImznZnm+uTtC/VtummJgH
 OzwI13Mf30/zpDxn+8cLa3WyZ6zkmaXB+Is2M14/7d15mefVoymvV4AXGcThtZ8LyIMT
 xEDjZVBj99sSAN/N5JlN9BS9+ZcTPzKQiQ7IZKaAHU/2q+Zc2lzSxEVwgKLXXZlRs+Xd
 z5PQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1731543264; x=1732148064;
 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=JmjyeJ3NyJzEDSb/rKGkJOOeIRgISsKBzXSi7SCrSRY=;
 b=M8giCBVzPzbT0X5BqJ6+N+RwhzVztuN5P+FIFPX+LXgFYNtEhMrex3pxXOdwwu1ZWR
 woDhwDvjTlxI2gM4cnsSFBuvFT8w1qIoEjvgRhfsAgR34e14z0V7deIULwis+H48xdl3
 ZTlKQZRbf107qIThCWmQ1BlQcHmXFcTpsrAenpiz77Bi43/+bXQ9VgSM5iecaCz5hkAn
 zRqFvcKIL0ob58VlMBq9KgPfJZc/DRS/MVgMAXJRps82Qa1qCKBdYUdxHk6ldUu1TxB7
 LAKXMDMqE2v6hP2ix+Ac9GxjM8UjgeifPeDtOX8lXwOJQIVGX0fUZN5BAvEgZ0v/2zq8
 zfwg==
X-Gm-Message-State: AOJu0YzMSPiP7/9Kla4LJxj7nCmGxtLSZNxJhhTWLQjxWWlA1TFopQBE
 xV6Uxy1jajfFn2Dr/UySkU6m0NTCKtHUM5eh5AIHT/c1cYErKmha1OKsLeYs8RvBG3drLyZ2wkK
 K
X-Google-Smtp-Source: AGHT+IFZzkNvN22uSPZgjX/drt+2ofg+53f0Ac80HPxqr4KxucAzD908ijXahV7Uruz7XtTNvzo/yQ==
X-Received: by 2002:aa7:8882:0:b0:720:2e44:8781 with SMTP id
 d2e1a72fcca58-724132bec51mr27994147b3a.11.1731543263726; 
 Wed, 13 Nov 2024 16:14:23 -0800 (PST)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 d2e1a72fcca58-7246a9a81a9sm9280b3a.99.2024.11.13.16.14.22
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 13 Nov 2024 16:14:23 -0800 (PST)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, getelson@nvidia.com,
 Ori Kam <orika@nvidia.com>, Aman Singh <aman.deep.singh@intel.com>
Subject: [RFC 08/10] app/test-pmd: avoid potential outside of array reference
Date: Wed, 13 Nov 2024 16:12:20 -0800
Message-ID: <20241114001403.147609-9-stephen@networkplumber.org>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20241114001403.147609-1-stephen@networkplumber.org>
References: <20241114001403.147609-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
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 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