From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id B02062B89 for ; Thu, 7 Dec 2017 15:48:14 +0100 (CET) Received: from core.dev.6wind.com (unknown [10.0.0.1]) by proxy.6wind.com (Postfix) with ESMTPS id BBB4510FAA6; Thu, 7 Dec 2017 15:40:09 +0100 (CET) Received: from [10.16.0.195] (helo=6wind.com) by core.dev.6wind.com with smtp (Exim 4.84_2) (envelope-from ) id 1eMxT1-00061i-BF; Thu, 07 Dec 2017 15:48:04 +0100 Received: by 6wind.com (sSMTP sendmail emulation); Thu, 07 Dec 2017 15:48:03 +0100 Date: Thu, 7 Dec 2017 15:48:03 +0100 From: Olivier MATZ To: Xueming Li Cc: dev@dpdk.org Message-ID: <20171207144802.sgj33veeehxixhfk@glumotte.dev.6wind.com> References: <20171115155402.9967-1-xuemingl@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171115155402.9967-1-xuemingl@mellanox.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] [PATCH] lib/cmdline: init parse result memeory 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: Thu, 07 Dec 2017 14:48:14 -0000 On Wed, Nov 15, 2017 at 11:54:02PM +0800, Xueming Li wrote: > Initialize binary result memory before parsing to avoid garbage in > parsing result. > > Signed-off-by: Xueming Li > --- > lib/librte_cmdline/cmdline_parse.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c > index 3e12ee54f..9124758f1 100644 > --- a/lib/librte_cmdline/cmdline_parse.c > +++ b/lib/librte_cmdline/cmdline_parse.c > @@ -267,6 +267,8 @@ cmdline_parse(struct cmdline *cl, const char * buf) > if (!cl || !buf) > return CMDLINE_PARSE_BAD_ARGS; > > + memset(tmp_result.buf, 0, sizeof(tmp_result.buf)); > + > ctx = cl->ctx; > > /* Did you see an issue (a bug or a crash) without the memset()? Or is it to avoid filling unused fields in the parsed struct? I'm not sure if your patch is enough: cmdline_parse() calls match_inst() for each registered command. If a command partially matches (only the first tokens), the buffer is modified. So the next one will start with a dirty buffer. I suggest to put the memset() in match_inst() instead. Something like this: if (resbuf != NULL) memset(resbuf, 0, resbuf_size); It will reset the buffer before using it. Olivier