[dpdk-dev] [PATCH v2] lib/cmdline: init CLI parsing memory

Xueming(Steven) Li xuemingl at mellanox.com
Tue Dec 26 13:57:41 CET 2017


HI Olivier,

By reading p1 comments carefully, looks like the pointer to result buffer issue
not resolved by result copy. How about this:

@@ -263,6 +263,7 @@
 #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,13 @@
 		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, sizeof(result.buf));
 
 		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 +330,7 @@
 				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 */

Merry Christmas

Xueming(Steven)

> -----Original Message-----
> From: Olivier MATZ [mailto:olivier.matz at 6wind.com]
> Sent: Thursday, December 14, 2017 11:36 PM
> To: Xueming(Steven) Li <xuemingl at mellanox.com>
> Cc: Adrien Mazarguil <adrien.mazarguil at 6wind.com>; dev at dpdk.org
> Subject: Re: [PATCH v2] lib/cmdline: init CLI parsing memory
> 
> Hi Xueming,
> 
> On Sat, Dec 09, 2017 at 11:39:23PM +0800, Xueming Li wrote:
> > Initialize result memory every time before parsing. Also save
> > successfully parsed result before further ambiguous command detection
> > to avoid result being tainted by later parsing.
> >
> > Signed-off-by: Xueming Li <xuemingl at mellanox.com>
> 
> I'm ok with the content of the patch, but this has 2 be split in 2 commits,
> which fixes different things.
> 
> 1/ cmdline: fix dynamic tokens parsing
> 
>    [contains what Adrien suggested = all your patch but memset]
> 
>    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 renames the buffers, and ensures that the pointers
>    point to the valid location, by recopying the buffer before
>    invoking f().
> 
>    Fixes: 9b3fbb051d2e ("cmdline: fix parsing")
>    Cc: stable at dpdk.org
> 
> 
> 2/ cmdline: avoid garbage in unused fields of parsed result
> 
>    [contains the memset() only]
> 
>    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 at dpdk.org
> 
> 
> Thoughts?
> Adrien, are you also ok?
> 
> Thanks,
> Olivier


More information about the dev mailing list