[dpdk-dev] cmdline: avoid garbage in unused fields of parsed result

Message ID 20180120032631.132978-1-xuemingl@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Xueming Li Jan. 20, 2018, 3:26 a.m. UTC
  The result buffer was not initialized before parsing, inducing garbage
in unused fields or padding of the parsed structure.

Initialize the result buffer each time before parsing.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org
Signed-off-by: Xueming Li <xuemingl@mellanox.com>
---
 lib/librte_cmdline/cmdline_parse.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Olivier Matz Jan. 22, 2018, 1:14 p.m. UTC | #1
On Sat, Jan 20, 2018 at 11:26:31AM +0800, Xueming Li wrote:
> The result buffer was not initialized before parsing, inducing garbage
> in unused fields or padding of the parsed structure.
> 
> Initialize the result buffer each time before parsing.
> 
> Fixes: af75078fece3 ("first public release")
> Cc: stable@dpdk.org
> Signed-off-by: Xueming Li <xuemingl@mellanox.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>
  
Thomas Monjalon Jan. 25, 2018, 10:17 p.m. UTC | #2
22/01/2018 14:14, Olivier Matz:
> On Sat, Jan 20, 2018 at 11:26:31AM +0800, Xueming Li wrote:
> > The result buffer was not initialized before parsing, inducing garbage
> > in unused fields or padding of the parsed structure.
> > 
> > Initialize the result buffer each time before parsing.
> > 
> > Fixes: af75078fece3 ("first public release")
> > Cc: stable@dpdk.org
> > Signed-off-by: Xueming Li <xuemingl@mellanox.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index c74b146fc..7f799f94d 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -168,6 +168,8 @@  match_inst(cmdline_parse_inst_t *inst, const char *buf,
 	int n = 0;
 	struct cmdline_token_hdr token_hdr;
 
+	if (resbuf != NULL)
+		memset(resbuf, 0, resbuf_size);
 	/* check if we match all tokens of inst */
 	while (!nb_match_token || i < nb_match_token) {
 		token_p = get_token(inst, i);