diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-07-04 18:53:35 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-10-03 14:45:04 +0400 |
commit | 90a6d17bed2ea1571ee74aff294e4584168a8e9f (patch) | |
tree | a06d70fc1342fd4ba0e15931a18eeb3788634bc7 | |
parent | dafd95053611aa14dda40266857608d12ddce658 (diff) |
chardev: avoid crash if no associated address
A socket chardev may not have associated address (when adding client
fd manually for example). But on disconnect, updating socket filename
expects an address and may lead to this crash:
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388
388 switch (addr->type) {
(gdb) bt
#0 0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388
#1 0x0000555555d8c8aa in update_disconnected_filename (s=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:419
#2 0x0000555555d8c959 in tcp_chr_disconnect (chr=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:438
#3 0x0000555555d8cba1 in tcp_chr_hup (channel=0x555556b75690, cond=G_IO_HUP, opaque=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:482
#4 0x0000555555da596e in qio_channel_fd_source_dispatch (source=0x555556bb68b0, callback=0x555555d8cb58 <tcp_chr_hup>, user_data=0x555556b1ed00) at /home/elmarco/src/qq/io/channel-watch.c:84
Replace filename with a generic "disconnected:socket" in this case.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r-- | chardev/char-socket.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 7cd0ae2824..a75b46d9fe 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -423,8 +423,12 @@ static void update_disconnected_filename(SocketChardev *s) Chardev *chr = CHARDEV(s); g_free(chr->filename); - chr->filename = SocketAddress_to_str("disconnected:", s->addr, - s->is_listen, s->is_telnet); + if (s->addr) { + chr->filename = SocketAddress_to_str("disconnected:", s->addr, + s->is_listen, s->is_telnet); + } else { + chr->filename = g_strdup("disconnected:socket"); + } } /* NB may be called even if tcp_chr_connect has not been |