From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <yliu@fridaylinux.org>
Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48])
 by dpdk.org (Postfix) with ESMTP id 5129F90F6
 for <stable@dpdk.org>; Mon, 21 Aug 2017 11:35:18 +0200 (CEST)
Received: by mail-pg0-f48.google.com with SMTP id y129so96842901pgy.4
 for <stable@dpdk.org>; Mon, 21 Aug 2017 02:35:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=fridaylinux-org.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=u5CzPoH3nSg0pjqqB5y5pOCel326TBBXkWwc0HDW2jM=;
 b=LuUQnuN2OX2N0oOnHJm7Q9oDzCGcxv8sqJjhdq3L8vqYmQy5ELv51Ei3cwRtGaZhb1
 IaYVXRHziaOIESgG/BqzMt8xpUjAyv6V2ueAqk/3WAj3ZZF7upW3GqcxCPWxKbrEPlLg
 gSeFO6wTrIhrekL3gBTgGtDqRjn2T5mni3gxOgbdUYXbaD1M05B9geqp3kKprSzgeiVy
 eP+myybBP8XAxnZuF2CuRY0zFHrHP3v7xPPJZvqbxGReQOnouCk9wlLF+ujlRWEV8Ieo
 kSFszqJv84T3+XUQam5fQRC00pNM0kfxF7jydPjC+OfznjSC4uLTYurZUPVfJdeXBx4G
 3ESw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=u5CzPoH3nSg0pjqqB5y5pOCel326TBBXkWwc0HDW2jM=;
 b=ph2bOTbSUgr0OWi1bP0buSYg1DJ209xHyHpPghWIwV1KufzuSXm+nsO1Adc+p/eGQN
 PvAiqaLR6dExKSGrgomT88+7FErOCFCWCU22TENGAcrDBCh7elKkQujaytRU9Ksus8GW
 GOvJ7NF1JBbFHSL0ENrSlLYi4WjOO+kolXwSr7TqL1feio43Vd0MYN4VoUnugbxZ2mie
 b0RQgHyorhbaLwTF3sTTY4QIQrU6qntoLLBIe1dQgggeup/TMwCkC5FkZhDmnRZXZ3+2
 l7tDWVNrZPjt6l4Lq6Y2Xrcejief4naMDv9qXIjntbuIwT3niZsi0Tbm0pN1850Sw3Ae
 MGbg==
X-Gm-Message-State: AHYfb5iqs0lv4ipAbtdWqvmG4JSGebDxYm277Sf5x/2lWi7PcPZvoTmw
 XNcYCoLRSrmbvhjRvOJRdQ==
X-Received: by 10.98.214.81 with SMTP id r78mr2366036pfg.159.1503308117628;
 Mon, 21 Aug 2017 02:35:17 -0700 (PDT)
Received: from localhost.localdomain ([45.63.61.64])
 by smtp.gmail.com with ESMTPSA id 69sm23355087pfh.186.2017.08.21.02.35.13
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Mon, 21 Aug 2017 02:35:16 -0700 (PDT)
From: Yuanhan Liu <yliu@fridaylinux.org>
To: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: dpdk stable <stable@dpdk.org>,
	Yuanhan Liu <yliu@fridaylinux.org>
Date: Mon, 21 Aug 2017 17:30:40 +0800
Message-Id: <1503307878-16728-26-git-send-email-yliu@fridaylinux.org>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1503307878-16728-1-git-send-email-yliu@fridaylinux.org>
References: <1503307878-16728-1-git-send-email-yliu@fridaylinux.org>
Subject: [dpdk-stable] patch 'app/testpmd: fix token matching in flow
	command' has been queued to stable release 17.05.2
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 21 Aug 2017 09:35:18 -0000

Hi,

FYI, your patch has been queued to stable release 17.05.2

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 08/24/17. So please
shout if anyone has objections.

Thanks.

	--yliu

---
>>From 41d56fcb8454e9d6151998fcd5ebdaa432019200 Mon Sep 17 00:00:00 2001
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Date: Mon, 10 Jul 2017 14:09:36 +0200
Subject: [PATCH] app/testpmd: fix token matching in flow command

[ upstream commit a00cbb4586bdff936c81a9179a93b869c52e9b0c ]

While matching user input against a token name or any other fixed string,
comparison stops at the end of user input if shorter (e.g. "foo" matches
token name "foobar").

Although the unintended consequence of this behavior allows users to
abbreviate command names and various parameters yet generate valid
commands, the parser was not designed to support this and does not prevent
ambiguous tokens.

For instance, entering "i" for a pattern item matches "ipv4", "ipv6" and
"icmp" then defaults to one of them in an unspecified manner.

Prevent this behavior by taking the length of fixed strings into account.

Fixes: 19c90af6285c ("app/testpmd: add flow command")
Fixes: 5ac3502ed1be ("app/testpmd: add flow query command")
Fixes: abc3d81aca1b ("app/testpmd: add item raw to flow command")
Fixes: 05d34c6e9d2c ("app/testpmd: add queue actions to flow command")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index dfff8be..4d47e79 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -1573,6 +1573,19 @@ arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
 	return len;
 }
 
+/** Compare a string with a partial one of a given length. */
+static int
+strcmp_partial(const char *full, const char *partial, size_t partial_len)
+{
+	int r = strncmp(full, partial, partial_len);
+
+	if (r)
+		return r;
+	if (strlen(full) <= partial_len)
+		return 0;
+	return full[partial_len];
+}
+
 /**
  * Parse a prefix length and generate a bit-mask.
  *
@@ -1655,7 +1668,7 @@ parse_default(struct context *ctx, const struct token *token,
 	(void)ctx;
 	(void)buf;
 	(void)size;
-	if (strncmp(str, token->name, len))
+	if (strcmp_partial(token->name, str, len))
 		return -1;
 	return len;
 }
@@ -1898,7 +1911,7 @@ parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
 	if (ctx->curr != ACTION_RSS_QUEUE)
 		return -1;
 	i = ctx->objdata >> 16;
-	if (!strncmp(str, "end", len)) {
+	if (!strcmp_partial("end", str, len)) {
 		ctx->objdata &= 0xffff;
 		return len;
 	}
@@ -2033,7 +2046,7 @@ parse_action(struct context *ctx, const struct token *token,
 		const struct parse_action_priv *priv;
 
 		token = &token_list[next_action[i]];
-		if (strncmp(token->name, str, len))
+		if (strcmp_partial(token->name, str, len))
 			continue;
 		priv = token->priv;
 		if (!priv)
@@ -2373,7 +2386,7 @@ parse_boolean(struct context *ctx, const struct token *token,
 	if (!arg)
 		return -1;
 	for (i = 0; boolean_name[i]; ++i)
-		if (!strncmp(str, boolean_name[i], len))
+		if (!strcmp_partial(boolean_name[i], str, len))
 			break;
 	/* Process token as integer. */
 	if (boolean_name[i])
-- 
2.7.4