[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/29] char: don't skip client cleanup if 'connected'
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 04/29] char: don't skip client cleanup if 'connected' flag is unset |
Date: |
Wed, 18 Oct 2017 18:11:56 +0200 |
From: "Daniel P. Berrange" <address@hidden>
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 <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
chardev/char-socket.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index e65148f..53eda8e 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]);
@@ -394,22 +390,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 emit_close = s->connected;
tcp_chr_free_connection(chr);
- if (s->listen_ioc) {
+ if (s->listen_ioc && s->listen_tag == 0) {
s->listen_tag = qio_channel_add_watch(
QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL);
}
update_disconnected_filename(s);
- qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
+ if (emit_close) {
+ qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
+ }
if (s->reconnect_time) {
qemu_chr_socket_restart_timer(chr);
}
--
1.8.3.1
- [Qemu-devel] [PULL 00/29] Misc patches for 2017-10-18, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 02/29] scsi-disk: support reporting of rotation rate, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 04/29] char: don't skip client cleanup if 'connected' flag is unset,
Paolo Bonzini <=
- [Qemu-devel] [PULL 01/29] checkpatch: refine mode selection, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 07/29] memory: fix off-by-one error in memory_region_notify_one(), Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 05/29] exec: add page_mask for flatview_do_translate, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 03/29] ide: support reporting of rotation rate, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 06/29] exec: simplify address_space_get_iotlb_entry, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 08/29] pc: make sure that plugged CPUs are of the same type, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 09/29] disas: Always initialize read_memory_inner_func properly, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 10/29] build: remove CONFIG_LIBDECNUMBER, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 13/29] tco: add trace events, Paolo Bonzini, 2017/10/18
- [Qemu-devel] [PULL 11/29] nios2: define tcg_env, Paolo Bonzini, 2017/10/18