From 274c3b52e10466a4771d591f6298ef61e8354ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Mon, 27 Apr 2015 17:03:14 +0200 Subject: [PATCH 1/5] Strip brackets from vnc host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit v2.2.0-1530-ge556032 vnc: switch to inet_listen_opts bypassed the use of inet_parse in inet_listen, making literal IPv6 addresses enclosed in brackets fail: qemu-kvm: -vnc [::1]:0: Failed to start VNC server on `(null)': address resolution failed for [::1]:5900: Name or service not known Strip the brackets to make it work again. Signed-off-by: Ján Tomko Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/vnc.c b/ui/vnc.c index 9f8ecd0c33..2dccae96c6 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3482,7 +3482,14 @@ void vnc_display_open(const char *id, Error **errp) h = strrchr(vnc, ':'); if (h) { - char *host = g_strndup(vnc, h - vnc); + char *host; + size_t hlen = h - vnc; + + if (vnc[0] == '[' && vnc[hlen - 1] == ']') { + host = g_strndup(vnc + 1, hlen - 2); + } else { + host = g_strndup(vnc, hlen); + } qemu_opt_set(sopts, "host", host, &error_abort); qemu_opt_set(wsopts, "host", host, &error_abort); qemu_opt_set(sopts, "port", h+1, &error_abort); From 2b2c1a38eeaba5d8bfe92281e9e680361e09ee3b Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 1 May 2015 11:44:46 +0100 Subject: [PATCH 2/5] ui: remove check for failure of qemu_acl_init() The qemu_acl_init() function has long since stopped being able to return NULL, since g_malloc will abort on OOM. As such the checks for NULL were unreachable code. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 2dccae96c6..076355d9c5 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3609,10 +3609,6 @@ void vnc_display_open(const char *id, Error **errp) aclname = g_strdup_printf("vnc.%s.x509dname", vs->id); } vs->tls.acl = qemu_acl_init(aclname); - if (!vs->tls.acl) { - fprintf(stderr, "Failed to create x509 dname ACL\n"); - exit(1); - } g_free(aclname); } #endif @@ -3626,10 +3622,6 @@ void vnc_display_open(const char *id, Error **errp) aclname = g_strdup_printf("vnc.%s.username", vs->id); } vs->sasl.acl = qemu_acl_init(aclname); - if (!vs->sasl.acl) { - fprintf(stderr, "Failed to create username ACL\n"); - exit(1); - } g_free(aclname); } #endif From 3d00ac1a2ee0294fc3d460e6013a5cdd9c73ea6c Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 5 May 2015 11:07:17 -0400 Subject: [PATCH 3/5] vnc: Don't assert if opening unix socket fails Reproducer: $ qemu-system-x86_64 -display vnc=unix:/root/i-cant-access-you.sock qemu-system-x86_64: iohandler.c:60: qemu_set_fd_handler2: Assertion `fd >= 0' failed. Aborted (core dumped) Signed-off-by: Cole Robinson Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/vnc.c b/ui/vnc.c index 076355d9c5..fe4cd759a1 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3684,6 +3684,9 @@ void vnc_display_open(const char *id, Error **errp) /* listen for connects */ if (strncmp(vnc, "unix:", 5) == 0) { vs->lsock = unix_listen(vnc+5, NULL, 0, errp); + if (vs->lsock < 0) { + goto fail; + } vs->is_unix = true; } else { vs->lsock = inet_listen_opts(sopts, 5900, errp); From bc119048d7377ec8335ecde5946df629a1b72b46 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 5 May 2015 11:07:18 -0400 Subject: [PATCH 4/5] vnc: Tweak error when init fails Before: qemu-system-x86_64: -display vnc=unix:/root/foo.sock: Failed to start VNC server on `(null)': Failed to bind socket to /root/foo.sock: Permission denied After: qemu-system-x86_64: -display vnc=unix:/root/foo.sock: Failed to start VNC server: Failed to bind socket to /root/foo.sock: Permission denied Rather than tweak the string possibly show unix: value as well, just drop the explicit display reporting. We already get the cli string in the error message, that should be sufficient. Signed-off-by: Cole Robinson Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index fe4cd759a1..1013ea5c45 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3779,8 +3779,7 @@ int vnc_init_func(QemuOpts *opts, void *opaque) vnc_display_init(id); vnc_display_open(id, &local_err); if (local_err != NULL) { - error_report("Failed to start VNC server on `%s': %s", - qemu_opt_get(opts, "display"), + error_report("Failed to start VNC server: %s", error_get_pretty(local_err)); error_free(local_err); exit(1); From 0ef705a2653f09c15e44a644a98b6febc761431e Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 5 May 2015 11:07:19 -0400 Subject: [PATCH 5/5] qemu-sockets: Report explicit error if unlink fails Consider this case: $ ls -ld ~/root-owned/ drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/ $ ls -l ~/root-owned/foo.sock -rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock $ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use ...which is techinically true, but the real error is that we failed to unlink. So report it. This may seem pathological but it's a real possibility via libvirt. Signed-off-by: Cole Robinson Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- util/qemu-sockets.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 87c9bc6c68..22c8c4c5d5 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -729,7 +729,12 @@ int unix_listen_opts(QemuOpts *opts, Error **errp) qemu_opt_set(opts, "path", un.sun_path, &error_abort); } - unlink(un.sun_path); + if ((access(un.sun_path, F_OK) == 0) && + unlink(un.sun_path) < 0) { + error_setg_errno(errp, errno, + "Failed to unlink socket %s", un.sun_path); + goto err; + } if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { error_setg_errno(errp, errno, "Failed to bind socket to %s", un.sun_path); goto err;