From patchwork Sat Jan 20 02:25:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueming Li X-Patchwork-Id: 34145 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0E0EF1B1E1; Sat, 20 Jan 2018 03:26:14 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 85A301B1BE for ; Sat, 20 Jan 2018 03:26:12 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from xuemingl@mellanox.com) with ESMTPS (AES256-SHA encrypted); 20 Jan 2018 04:26:08 +0200 Received: from dev-r630-06.mtbc.labs.mlnx (dev-r630-06.mtbc.labs.mlnx [10.12.205.180]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w0K2Q7VF006758; Sat, 20 Jan 2018 04:26:07 +0200 Received: from dev-r630-06.mtbc.labs.mlnx (localhost [127.0.0.1]) by dev-r630-06.mtbc.labs.mlnx (8.14.7/8.14.7) with ESMTP id w0K2Q562131536; Sat, 20 Jan 2018 10:26:05 +0800 Received: (from xuemingl@localhost) by dev-r630-06.mtbc.labs.mlnx (8.14.7/8.14.7/Submit) id w0K2Q43S131535; Sat, 20 Jan 2018 10:26:04 +0800 From: Xueming Li To: Olivier MATZ Cc: Xueming Li , dev@dpdk.org, Adrien Mazarguil , stable@dpdk.org Date: Sat, 20 Jan 2018 10:25:54 +0800 Message-Id: <20180120022554.131490-1-xuemingl@mellanox.com> X-Mailer: git-send-email 2.13.3 Subject: [dpdk-dev] [PATCH] cmdline: fix dynamic tokens parsing 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" When using dynamic tokens, the result buffer contains pointers to some location inside the result buffer. When the content of the temporary buffer is copied in the final one, these pointers still point to the temporary buffer. This works until the temporary buffer is kept intact, but the next commit introduces a memset() that breaks this assumption. This commit keeps the successfully parsed buffers, and ensures that the pointers point to the valid location, by using temp buffer for following parsing. Fixes: 9b3fbb051d2e ("cmdline: fix parsing") Cc: stable@dpdk.org Signed-off-by: Xueming Li --- lib/librte_cmdline/cmdline_parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c index 3e12ee54f..c74b146fc 100644 --- a/lib/librte_cmdline/cmdline_parse.c +++ b/lib/librte_cmdline/cmdline_parse.c @@ -263,6 +263,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) #ifdef RTE_LIBRTE_CMDLINE_DEBUG char debug_buf[BUFSIZ]; #endif + char *result_buf = result.buf; if (!cl || !buf) return CMDLINE_PARSE_BAD_ARGS; @@ -312,16 +313,14 @@ cmdline_parse(struct cmdline *cl, const char * buf) debug_printf("INST %d\n", inst_num); /* fully parsed */ - tok = match_inst(inst, buf, 0, tmp_result.buf, - sizeof(tmp_result.buf)); + tok = match_inst(inst, buf, 0, result_buf, + CMDLINE_PARSE_RESULT_BUFSIZE); if (tok > 0) /* we matched at least one token */ err = CMDLINE_PARSE_BAD_ARGS; else if (!tok) { debug_printf("INST fully parsed\n"); - memcpy(&result, &tmp_result, - sizeof(result)); /* skip spaces */ while (isblank2(*curbuf)) { curbuf++; @@ -332,6 +331,7 @@ cmdline_parse(struct cmdline *cl, const char * buf) if (!f) { memcpy(&f, &inst->f, sizeof(f)); memcpy(&data, &inst->data, sizeof(data)); + result_buf = tmp_result.buf; } else { /* more than 1 inst matches */