From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by dpdk.org (Postfix) with ESMTP id 8235A7CAA for ; Mon, 10 Jul 2017 14:10:16 +0200 (CEST) Received: by mail-wr0-f175.google.com with SMTP id k67so135648669wrc.2 for ; Mon, 10 Jul 2017 05:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/M3EPL2YkdKMKmAQh7VlRVMOIK3J8gTd1/PL90CqbEI=; b=I7kIafI2o0CDmgCI+S3BNCEx7/2XMg9AnZlrYVSRqkWOmwqB0IoGf3ChxkifEoCeNO Qt7+OzGjQWvVsG0UpldIA5SKWY7bxHkWA2UvZtRAEqWp2rG+PXUsdxC+SytWvgEa1Jkl cN1V7iTBik0YDjXYjoZ+a+ybnkgPB+CHa0JOKGGsKGG2uBvifQ35rzyWP1KOC0x4QiEJ es2YQFUoCY/1d4/VlPaTa/63E4vUdl0AHPbguYqjtpw8NUPtCCrrPZZxMXPPl3Swzilg 1ZfOZ8Qc07eg1eypIPHabfHu7OkcElSPtUEfItiR2l2bCPbmrousSv615QNBWU3b0ANK cSDw== 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=/M3EPL2YkdKMKmAQh7VlRVMOIK3J8gTd1/PL90CqbEI=; b=Wtjl1QgKkwoQRcsgV7oXldBWNqJnQkoVukF9RL+cVB6lgb2eg9lEeB8whlYKSvOFhS kV3BvAMOhAda6hDe/ceEXf0R2EzKAlR52jdgQ44UlDURyMUZ16QksL284vZIq/+fFDme kQuKivJcfPTdDrtMzKHbHl/cTQTbbxWUry5CTm/Z4HqVUqExiDdLBMHY98Qyro9Yl70f gAuRN94N5BUjN/B6zyRK7LqgpV+U3rmYb/w7j8/8Hs4qqd6G+AIv632VMX+XR+Jb37WU Nf36BZa/0Nvx15I/oQ6bkBHSxsQ5Fqrm1zbh2vXWjTjC5AfxtY/HbN8QeLi005aT9Gab YJ0g== X-Gm-Message-State: AIVw110xus9ioWWsbJMRWB0IaNL4Ycbwk28Io4ioDVu8E86K08cCk3xF xDyjR83VlRFYDdu0 X-Received: by 10.223.134.169 with SMTP id 38mr6681958wrx.92.1499688615948; Mon, 10 Jul 2017 05:10:15 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id w198sm11860279wme.21.2017.07.10.05.10.14 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 10 Jul 2017 05:10:15 -0700 (PDT) From: Adrien Mazarguil To: Olivier Matz Cc: dev@dpdk.org, stable@dpdk.org Date: Mon, 10 Jul 2017 14:09:36 +0200 Message-Id: <2065c72b2ec6e1377beff72d246ae23fb533ab78.1499687422.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: <327b5be12221f51fbf3a6d8e9d155de786992388.1497521374.git.adrien.mazarguil@6wind.com> Subject: [dpdk-stable] [PATCH v3 3/3] app/testpmd: fix token matching in flow command X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jul 2017 12:10:16 -0000 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") Cc: stable@dpdk.org Signed-off-by: Adrien Mazarguil --- 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 9533df1..a17a004 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -1624,6 +1624,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. * @@ -1706,7 +1719,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; } @@ -1949,7 +1962,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; } @@ -2084,7 +2097,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) @@ -2451,7 +2464,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.1.4