All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>
Cc: xen-devel@lists.xenproject.org, Ian Jackson <ian.jackson@eu.citrix.com>
Subject: Re: [RFC v2 4/9] libxl_qmp: Move the buffer realloc to the same scope level as read
Date: Mon, 23 Apr 2018 15:50:27 +0100	[thread overview]
Message-ID: <20180423145027.GB1980@perard> (raw)
In-Reply-To: <20180423090339.g7ikb3h2ss25afmj@citrix.com>

On Mon, Apr 23, 2018 at 10:03:39AM +0100, Wei Liu wrote:
> On Mon, Apr 16, 2018 at 06:32:22PM +0100, Anthony PERARD wrote:
> > In qmp_next(), the inner loop should only try to parse messages from
> > QMP, if there is more than one.
> > 
> > The handling of the receive buffer ('incomplete'), should be done at the
> > same scope level as read(). It doesn't need to be handle more that once
> > after a read.
> > 
> 
> In general I agree this is a better idea than the current code.
> 
> > Before this patch, when on message what handled, the inner loop would
> 
> Sorry, I failed to parse "when on message what handled".

I probably wanted to write: "when one message was handled". Is this
better?

> > restart by adding the 'buffer' into 'incomplete' (after reallocation).
> > Since 'rd' was not reset, the buffer would be strcat a second time.
> > After that, the stream from the QMP server would have syntax error, and
> > the parsor would throw errors.
> > 
> > This is unlikely to happen as the receive buffer is very large. And
> > receiving two messages in a row is unlikely. In the current case, this
> > could be an event and a response to a command.
> > 
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> > ---
> >  tools/libxl/libxl_qmp.c | 31 ++++++++++++++++---------------
> >  1 file changed, 16 insertions(+), 15 deletions(-)
> > 
> > diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> > index 4d207c3842..a25f445fb6 100644
> > --- a/tools/libxl/libxl_qmp.c
> > +++ b/tools/libxl/libxl_qmp.c
> > @@ -524,23 +524,24 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
> >  
> >          DEBUG_REPORT_RECEIVED(qmp->domid, qmp->buffer, (int)rd);
> >  
> > +        if (incomplete) {
> > +            size_t current_pos = s - incomplete;
> > +            incomplete = libxl__realloc(gc, incomplete,
> > +                                        incomplete_size + rd + 1);
> > +            strncat(incomplete + incomplete_size, qmp->buffer, rd);
> > +            s = incomplete + current_pos;
> 
> This can be dropped, because s is not changed. It is just the reversal
> of what is a few lines above.

No, realloc may change the location of the allocated memory. So, between
"current_pos = s - incomplete" and "s = incomplete + current_pos", the
value of 'incomplete' may have changed.

> > +            incomplete_size += rd;
> > +            s_end = incomplete + incomplete_size;
> > +        } else {
> > +            incomplete = libxl__strndup(gc, qmp->buffer, rd);
> > +            incomplete_size = rd;
> > +            s = incomplete;
> > +            s_end = s + rd;
> > +            rd = 0;
> 
> This can be dropped.
> 
> And I think we should take this change to change "incomplete" to
> something more meaningful, like "qmp_msg_buf".

I think that can be done.


-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-04-23 14:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 17:32 [RFC v2 0/9] libxl: Enable save/restore/migration of a restricted QEMU Anthony PERARD
2018-04-16 17:32 ` [RFC v2 1/9] libxl_event: Fix DEBUG prints Anthony PERARD
2018-04-19  8:17   ` Wei Liu
2018-04-19 11:01     ` Anthony PERARD
2018-04-16 17:32 ` [RFC v2 2/9] libxl_qmp: Documentation of the logic of the QMP client Anthony PERARD
2018-04-19  8:19   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 3/9] libxl_qmp: Fix use of DEBUG_RECEIVED Anthony PERARD
2018-04-19  8:22   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 4/9] libxl_qmp: Move the buffer realloc to the same scope level as read Anthony PERARD
2018-04-23  9:03   ` Wei Liu
2018-04-23 14:50     ` Anthony PERARD [this message]
2018-04-23 15:01       ` Wei Liu
2018-04-16 17:32 ` [RFC v2 5/9] libxl: Learned to send FD through QMP to QEMU Anthony PERARD
2018-04-23  9:04   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 6/9] libxl: Have QEMU save its state to a file descriptor Anthony PERARD
2018-04-23  9:20   ` Wei Liu
2018-04-23 15:45     ` Anthony PERARD
2018-04-24  9:37       ` Wei Liu
2018-04-24  9:46   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 7/9] libxl_qmp: Implement query-status command Anthony PERARD
2018-04-23  9:24   ` Wei Liu
2018-04-16 17:32 ` [RFC v2 8/9] HACK libxl_exec: Check QEMU status via QMP instead of xenstore Anthony PERARD
2018-04-16 18:09   ` Anthony PERARD
2018-04-17  9:18   ` Anthony PERARD
2018-04-20 18:37   ` Ian Jackson
2018-04-23 16:54     ` Anthony PERARD
2018-04-23 16:56       ` Ian Jackson
2018-04-16 17:32 ` [RFC v2 9/9] libxl_qmp: Add a warning to not trust QEMU Anthony PERARD

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=20180423145027.GB1980@perard \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.