From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: QEMU <qemu-devel@nongnu.org>, Paolo Bonzini <pbonzini@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] char: don't skip client cleanup if 'connected' flag is unset
Date: Thu, 5 Oct 2017 16:40:23 +0100 [thread overview]
Message-ID: <20171005154023.GJ12106@redhat.com> (raw)
In-Reply-To: <CAJ+F1C+t+1Zf8CTsWMddS6WP4jFXDUqex_wa9kJtZW-VkzgEvg@mail.gmail.com>
On Thu, Oct 05, 2017 at 05:35:39PM +0200, Marc-André Lureau wrote:
> Hi
>
> On Thu, Oct 5, 2017 at 5:28 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
> > The tcp_chr_free_connection & tcp_chr_disconnect methods both
> > skip all of their cleanup work unless the 's->connected' flag
> > is set. This flag is set when the incoming client connection
> > is ready to use. Crucially this is *after* the TLS handshake
> > has been completed. So if the TLS handshake fails and we try
> > to cleanup the failed client, all the cleanup is skipped as
> > 's->connected' is still false.
> >
> > The only important thing that should be skipped in this case
> > is sending of the CHR_EVENT_CLOSED, because we never got as
> > far as sending the corresponding CHR_EVENT_OPENED. Every other
> > bit of cleanup can be robust against being called even when
> > s->connected is false.
> >
> > Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> > ---
> > chardev/char-socket.c | 31 +++++++++++++++++--------------
> > 1 file changed, 17 insertions(+), 14 deletions(-)
> >
> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> > index e65148fe97..a34d4d72c2 100644
> > --- a/chardev/char-socket.c
> > +++ b/chardev/char-socket.c
> > @@ -332,10 +332,6 @@ static void tcp_chr_free_connection(Chardev *chr)
> > SocketChardev *s = SOCKET_CHARDEV(chr);
> > int i;
> >
> > - if (!s->connected) {
> > - return;
> > - }
> > -
> > if (s->read_msgfds_num) {
> > for (i = 0; i < s->read_msgfds_num; i++) {
> > close(s->read_msgfds[i]);
> > @@ -347,10 +343,14 @@ static void tcp_chr_free_connection(Chardev *chr)
> >
> > tcp_set_msgfds(chr, NULL, 0);
> > remove_fd_in_watch(chr);
> > - object_unref(OBJECT(s->sioc));
> > - s->sioc = NULL;
> > - object_unref(OBJECT(s->ioc));
> > - s->ioc = NULL;
> > + if (s->sioc) {
> > + object_unref(OBJECT(s->sioc));
> > + s->sioc = NULL;
> > + }
> > + if (s->ioc) {
> > + object_unref(OBJECT(s->ioc));
> > + s->ioc = NULL;
> > + }
>
> object_unref() and OBJECT() are null-safe.
>
> > g_free(chr->filename);
> > chr->filename = NULL;
> > s->connected = 0;
> > @@ -394,22 +394,25 @@ static void update_disconnected_filename(SocketChardev *s)
> > s->is_listen, s->is_telnet);
> > }
> >
> > +/* NB may be called even if tcp_chr_connect has not been
> > + * reached, due to TLS or telnet initialization failure,
> > + * so can *not* assume s->connected == true
> > + */
> > static void tcp_chr_disconnect(Chardev *chr)
> > {
> > SocketChardev *s = SOCKET_CHARDEV(chr);
> > -
> > - if (!s->connected) {
> > - return;
> > - }
> > + bool emitClose = s->connected;
>
> ewh, which code style do you pick today? :)
Which bit don't you like ? The 'bool' or the camelCase, or both ?
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2017-10-05 15:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-05 15:28 [Qemu-devel] [PATCH] char: don't skip client cleanup if 'connected' flag is unset Daniel P. Berrange
2017-10-05 15:35 ` Eric Blake
2017-10-05 15:35 ` Marc-André Lureau
2017-10-05 15:40 ` Daniel P. Berrange [this message]
2017-10-05 15:48 ` Marc-André Lureau
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=20171005154023.GJ12106@redhat.com \
--to=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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.