From: Olivier Matz <olivier.matz@6wind.com>
To: "Xueming(Steven) Li" <xuemingl@mellanox.com>
Cc: Adrien Mazarguil <adrien.mazarguil@6wind.com>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH v2] lib/cmdline: init CLI parsing memory
Date: Fri, 19 Jan 2018 10:07:02 +0100 [thread overview]
Message-ID: <20180119090702.fpko3aiz27b3heau@platinum> (raw)
In-Reply-To: <VI1PR05MB1678497BEC4648EB45B1E300ACE80@VI1PR05MB1678.eurprd05.prod.outlook.com>
On Thu, Jan 18, 2018 at 04:29:59AM +0000, Xueming(Steven) Li wrote:
>
>
> > -----Original Message-----
> > From: Olivier Matz [mailto:olivier.matz@6wind.com]
> > Sent: Tuesday, January 16, 2018 8:46 PM
> > To: Xueming(Steven) Li <xuemingl@mellanox.com>
> > Cc: Adrien Mazarguil <adrien.mazarguil@6wind.com>; dev@dpdk.org
> > Subject: Re: [PATCH v2] lib/cmdline: init CLI parsing memory
> >
> > Hi Xueming,
> >
> > Sorry for the late response.
> >
> > On Tue, Dec 26, 2017 at 12:57:41PM +0000, Xueming(Steven) Li wrote:
> > > 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 we don't use tmp_result, it is maybe better to also replace
> > sizeof(result.buf) by CMDLINE_PARSE_RESULT_BUFSIZE
>
> Thanks, would like to send out new version soon
>
> >
> > >
> > > 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 */
> > >
> >
> >
> > I guess the issue you are talking about is the one described in
> > "cmdline: fix dynamic tokens parsing" in my previous description?
> >
> > I think this patch is ok, and is probably better than the initial
> > suggestion, because it avoids to copy the buffer. However, I don't
> > understand why the previous patch was wrong, can you detail?
>
> Let me quote your last email:
> " 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."
> If pointer exist in buffer, the new copy still pint to the old copy
> which very probably being changed.
In patch v2, I still think it was correct because there were 2 copies:
1/ tok = match_inst(inst, buf, 0, result.buf, sizeof(result.buf));
result is set, it may contain pointers to itself
2/ result_ok = result;
result is copied in result_ok
result_ok may contain pointer to result
3/ other calls to match_inst(inst, buf, 0, result...)
this can clobber the result buffer
4/ result = result_ok; // before calling f()
restores the content of result as it was in 1/
it may contain pointers to itself, which is valid
Was there another problem I missed?
Anyway, I think your v3 is better because it avoids buffer copies.
If it's ok for you, please send a v4 with the small updated regarding
sizeof(result.buf) -> CMDLINE_PARSE_RESULT_BUFSIZE.
Thanks,
Olivier
next prev parent reply other threads:[~2018-01-19 9:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 15:54 [dpdk-dev] [PATCH] lib/cmdline: init parse result memeory Xueming Li
2017-12-07 14:48 ` Olivier MATZ
2017-12-07 15:05 ` Xueming(Steven) Li
2017-12-07 15:35 ` Xueming(Steven) Li
2017-12-07 17:13 ` Adrien Mazarguil
2017-12-08 7:02 ` [dpdk-dev] [PATCH v1] lib/cmdline: init parse result memory Xueming Li
2017-12-08 12:27 ` Adrien Mazarguil
2017-12-08 13:51 ` Olivier MATZ
2017-12-08 14:50 ` Xueming(Steven) Li
2017-12-08 15:04 ` Adrien Mazarguil
2017-12-08 15:26 ` Olivier MATZ
2017-12-09 15:39 ` [dpdk-dev] [PATCH v2] lib/cmdline: init CLI parsing memory Xueming Li
2017-12-14 15:35 ` Olivier MATZ
2017-12-18 10:51 ` Adrien Mazarguil
2017-12-18 13:44 ` Xueming(Steven) Li
2017-12-26 12:57 ` Xueming(Steven) Li
2018-01-16 12:45 ` Olivier Matz
2018-01-18 4:29 ` Xueming(Steven) Li
2018-01-19 9:07 ` Olivier Matz [this message]
2018-01-19 18:18 ` Xueming(Steven) Li
2018-01-19 18:16 ` [dpdk-dev] [PATCH v3] cmdline: fix dynamic tokens parsing Xueming Li
2018-01-22 13:13 ` Olivier Matz
2018-01-25 22:14 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180119090702.fpko3aiz27b3heau@platinum \
--to=olivier.matz@6wind.com \
--cc=adrien.mazarguil@6wind.com \
--cc=dev@dpdk.org \
--cc=xuemingl@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).