From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id 3650A7CA3 for ; Mon, 10 Jul 2017 14:10:16 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id r103so136201795wrb.0 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=kbuu/GhOofXwtVG5rqieEpThNKlf3OvrwONY902Zv9tyoi0Fr+yNpuHBQUJSU6A/1m k3Rw2JFOjEGkqvi2DAkX2OaexXIppb5ZKR6dCM+FY84wzIes4N9LEug5YCRT071OtN03 GnrW9oYgwySDLzFEBD6x06DU4EAG4AQkJf8Z3HZ/bgLb9L76RT5A/GnkYTB7zdErkejC Z+pdeLgLPDTdcrqJ19SMnup9xY6LCvfurF0pPQqrwprWMpSQx1koqAvpKOLVVFpnscaa frAlUYTwYqDuuywY5PNC1I7tHe54W5Y/D2hGyJr86//CqnrzQ3tOvAfF4qxHS35SlPMP nFDA== X-Gm-Message-State: AIVw111VMYEtz1Us1UPWAEey9FMdaAUi1AKpcNYkfGOFPg3R84bJm4FS +2xetm/Om+XYMmiS 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-dev] [PATCH v3 3/3] app/testpmd: fix token matching in flow command X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions 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