From patchwork Thu Jun 15 10:15:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 25346 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id BC97A2BF1; Thu, 15 Jun 2017 12:16:02 +0200 (CEST) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by dpdk.org (Postfix) with ESMTP id E2D602BB9 for ; Thu, 15 Jun 2017 12:16:01 +0200 (CEST) Received: by mail-lf0-f49.google.com with SMTP id o83so6126653lff.3 for ; Thu, 15 Jun 2017 03:16:01 -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=KjMqhdw8oMq0kllkRF/cSzVQ3L6qxIYsTjL7pXNw3rE=; b=SzLigyupBUvWTaMBGGEvIqjq7Mf4MzcC1iLOklopi2qbi36sJdyAXV8tiQe/lmUe5P CkFuw3Yq29QcwtrAOeF+9hu1Qe6JJoytGY9nzEwcTrbkQT4GLUvm0NqmUZB76QbWz0lu A9fRYX0HJ/ilUPVy8o3u9+zrO7U8q4Q0FFSPB3AxmZsJlpRXUYO22++AFLQ4xAesfdL4 2SRIAfn9FxFbIYIHUVXqY7pctyXmYv0w+gAUE86fLeB8XqvEeqvPjK7sfOEb02LLLv8L YrY81ssDuVvbYq4gX64kPE6CUYy5OJNifZJLrgL9omB6p9P59wOYhx2t7SRxUaxt0OHe Lfzg== 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=KjMqhdw8oMq0kllkRF/cSzVQ3L6qxIYsTjL7pXNw3rE=; b=EalQRVZj6Yg+ZDtHWkeIf9XeWbbks+Ye7woKRO5Kmu9gjssL9qqMI7LdIa9VANOevY V9R2NvRa8gjSTJd21GXNsZMX4NtlxTd9PvdSI1Kv+rg0IBU2p6mb478hQYzQDm/9odCs 9pnFLsib0FXwHhNhmigsJhaDrsqHSJ2yQJGHEBWV20+NHB8Dny7Pa5FBfvr5ogLdyoAR Zc4jtD53cXpg33AjRJPLzvIunEneqr4/b94Ta0/jX3uT5VOR4oEQMJkU+vaF6SgQaDPJ ThJoLzIl1vZSdPOVz0yO7vkAN9Hj++z79gVncnHTgdAY70WDGyY8xAvVHchyBolQkMXJ x6yA== X-Gm-Message-State: AKS2vOzxNaNjXjVFx6pIJ9/t0FTq2+85D1e5QICstli5k0098gMzTAlP Oq3DKH5RN5poaibc X-Received: by 10.80.177.209 with SMTP id n17mr2922950edd.177.1497521760550; Thu, 15 Jun 2017 03:16:00 -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 j40sm1197937ede.0.2017.06.15.03.15.59 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 15 Jun 2017 03:15:59 -0700 (PDT) From: Adrien Mazarguil To: Bernard Iremonger , Olivier Matz Cc: dev@dpdk.org, stable@dpdk.org Date: Thu, 15 Jun 2017 12:15:48 +0200 Message-Id: <327b5be12221f51fbf3a6d8e9d155de786992388.1497521374.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1497348447-1167-1-git-send-email-bernard.iremonger@intel.com> References: <1497348447-1167-1-git-send-email-bernard.iremonger@intel.com> Subject: [dpdk-dev] [PATCH v2] librte_cmdline: fix parsing initialisation 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: "Bernard.Iremonger" The dyn_tokens array is initialised at the beginning of the cmdline_parse function. However when the inst_num variable is incremented later in the function the dyn_tokens array is not reinitialised so the tokens from the previous command are used. The solution is to initialise the dyn_tokens array in all while (inst) loops, before calling match_inst(). Fixes: 4fffc05a2b2c ("cmdline: support dynamic tokens") CC: stable@dpdk.org Signed-off-by: Bernard Iremonger Signed-off-by: Adrien Mazarguil --- Nice catch Bernard. This issue can be seen when implementing several flow-like commands in testpmd. While testing your original patch though, it appeared that it did not fully address the issue, as completion remained partially broken. Actually all match_inst() calls should be preceded by a memset(), so here's an updated version instead of requesting you to do these changes. --- lib/librte_cmdline/cmdline_parse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index b814880..c1d9f23 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -276,7 +276,6 @@ cmdline_parse(struct cmdline *cl, const char * buf) return CMDLINE_PARSE_BAD_ARGS; ctx = cl->ctx; - memset(&dyn_tokens, 0, sizeof(dyn_tokens)); /* * - look if the buffer contains at least one line @@ -321,6 +320,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) debug_printf("INST %d\n", inst_num); /* fully parsed */ + memset(&dyn_tokens, 0, sizeof(dyn_tokens)); tok = match_inst(inst, buf, 0, tmp_result.buf, sizeof(tmp_result.buf), &dyn_tokens); @@ -400,7 +400,6 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, debug_printf("%s called\n", __func__); memset(&token_hdr, 0, sizeof(token_hdr)); - memset(&dyn_tokens, 0, sizeof(dyn_tokens)); /* count the number of complete token to parse */ for (i=0 ; buf[i] ; i++) { @@ -423,6 +422,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, inst = ctx[inst_num]; while (inst) { /* parse the first tokens of the inst */ + memset(&dyn_tokens, 0, sizeof(dyn_tokens)); if (nb_token && match_inst(inst, buf, nb_token, NULL, 0, &dyn_tokens)) @@ -530,6 +530,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int *state, /* we need to redo it */ inst = ctx[inst_num]; + memset(&dyn_tokens, 0, sizeof(dyn_tokens)); if (nb_token && match_inst(inst, buf, nb_token, NULL, 0, &dyn_tokens)) goto next2;