Skip to contentSkip to conversation

vnc patch queue.

GIT PULL Applied Gerd Hoffmann 2 participants 9 messages Mar 12, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

Some vnc cleanups, more QemuOpts conversion fallout fixes.

please pull,
Gerd

The following changes since commit 9159eb9abc31e02797dc55998e71f12c06846d55:

Merge remote-tracking branch 'remotes/amit/tags/vser-for-2.3-1' into staging (2015-03-11 14:27:13 +0000)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-vnc-20150312-1

for you to fetch changes up to 81607cbfa433272d1f09bd0f0ae6c3b14f818972:

vnc: fix segmentation fault when invalid vnc parameters are specified (2015-03-12 09:09:10 +0100)

----------------------------------------------------------------
vnc: bugfixes and cleanups.

----------------------------------------------------------------
Daniel P. Berrange (1):
ui: fix regression in x509verify parameter for VNC server

Gerd Hoffmann (3):
vnc: drop display+ws_display from VncDisplay
vnc: remove dead code
vnc: switch to inet_listen_opts

Gonglei (3):
ui/console: fix OVERFLOW_BEFORE_WIDEN
vnc: avoid possible file handler leak
vnc: fix segmentation fault when invalid vnc parameters are specified

 ui/console.c       |   4 +-
 ui/vnc-auth-sasl.c |   2 +-
 ui/vnc.c           | 128 +++++++++++++++++++++++++++--------------------------
 ui/vnc.h           |   6 +--
 4 files changed, 72 insertions(+), 68 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 2/7] vnc: remove dead code

If vs->ws_enabled is set ws_display is non-NULL.

---
 ui/vnc.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
ui/vnc.c +2 -7
index 65ba1c0..bac44ce 100644
@@ -3627,13 +3627,8 @@ void vnc_display_open(const char *id, Error **errp)
             }
 #ifdef CONFIG_VNC_WS
             if (vs->ws_enabled) {
-                if (ws_display) {
-                    vs->lwebsock = inet_listen(ws_display, NULL, 0,
-                        SOCK_STREAM, 0, errp);
-                } else {
-                    vs->lwebsock = inet_listen(display, NULL, 0,
-                        SOCK_STREAM, 5700, errp);
-                }
+                vs->lwebsock = inet_listen(ws_display, NULL, 0,
+                                           SOCK_STREAM, 0, errp);
                 if (vs->lwebsock < 0) {
                     if (vs->lsock) {
                         close(vs->lsock);
Signature · 1 line
1.8.3.1
#2 lore raw

[Qemu-devel] [PULL 6/7] vnc: avoid possible file handler leak

In reply to Gerd Hoffmann

From: Gonglei <[email protected]>

vs->lsock may equal to 0, modify the check condition, avoid possible vs->lsock leak.

---
 ui/vnc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ui/vnc.c +1 -1
index b514777..1e95445 100644
@@ -3644,7 +3644,7 @@ void vnc_display_open(const char *id, Error **errp)
             if (vs->ws_enabled) {
                 vs->lwebsock = inet_listen_opts(wsopts, 0, errp);
                 if (vs->lwebsock < 0) {
-                    if (vs->lsock) {
+                    if (vs->lsock != -1) {
                         close(vs->lsock);
                         vs->lsock = -1;
                     }
Signature · 1 line
1.8.3.1
#3 lore raw

[Qemu-devel] [PULL 7/7] vnc: fix segmentation fault when invalid vnc parameters are specified

In reply to Gerd Hoffmann

From: Gonglei <[email protected]>

Reproducer:
#./qemu-system-x86_64 -vnc :0,ip
qemu-system-x86_64: -vnc :1,ip: Invalid parameter 'ip' Segmentation fault (core dumped)

---
 ui/vnc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
ui/vnc.c +6 -1
index 1e95445..6f9b718 100644
@@ -3703,8 +3703,13 @@ QemuOpts *vnc_parse_func(const char *str)
 {
     QemuOptsList *olist = qemu_find_opts("vnc");
     QemuOpts *opts = qemu_opts_parse(olist, str, 1);
-    const char *id = qemu_opts_id(opts);
+    const char *id;
 
+    if (!opts) {
+        return NULL;
+    }
+
+    id = qemu_opts_id(opts);
     if (!id) {
         /* auto-assign id if not present */
         vnc_auto_assign_id(olist, opts);
Signature · 1 line
1.8.3.1
#4 lore raw

[Qemu-devel] [PULL 5/7] ui/console: fix OVERFLOW_BEFORE_WIDEN

In reply to Gerd Hoffmann

From: Gonglei <[email protected]>

---
 ui/console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ui/console.c +2 -2
index 87af6b5..b15ca87 100644
@@ -1285,9 +1285,9 @@ DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
         linesize = width * PIXMAN_FORMAT_BPP(format) / 8;
     }
 
-    size = linesize * height;
+    size = (hwaddr)linesize * height;
     data = cpu_physical_memory_map(addr, &size, 0);
-    if (size != linesize * height) {
+    if (size != (hwaddr)linesize * height) {
         cpu_physical_memory_unmap(data, size, 0, 0);
         return NULL;
     }
Signature · 1 line
1.8.3.1
#5 lore raw

[Qemu-devel] [PULL 3/7] vnc: switch to inet_listen_opts

In reply to Gerd Hoffmann

Use inet_listen_opts instead of inet_listen. Allows us to drop some pointless indirection: Format strings just to parse them again later on.

---
 ui/vnc.c | 75 +++++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 41 insertions(+), 34 deletions(-)
ui/vnc.c +41 -34
index bac44ce..db8409b 100644
@@ -3322,13 +3322,14 @@ void vnc_display_open(const char *id, Error **errp)
 {
     VncDisplay *vs = vnc_display_find(id);
     QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id);
+    QemuOpts *sopts, *wsopts;
     const char *share, *device_id;
     QemuConsole *con;
     bool password = false;
     bool reverse = false;
     const char *vnc;
     const char *has_to;
-    char *display, *ws_display = NULL, *to = NULL;
+    char *h;
     bool has_ipv4 = false;
     bool has_ipv6 = false;
 #ifdef CONFIG_VNC_WS
@@ -3361,16 +3362,36 @@ void vnc_display_open(const char *id, Error **errp)
         return;
     }
 
-    has_to = qemu_opt_get(opts, "to");
-    if (has_to) {
-        to = g_strdup_printf(",to=%s", has_to);
+    sopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
+    wsopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
+
+    h = strrchr(vnc, ':');
+    if (h) {
+        char *host = g_strndup(vnc, h - vnc);
+        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);
+        g_free(host);
+    } else {
+        error_setg(errp, "no vnc port specified");
+        goto fail;
     }
+
+    has_to = qemu_opt_get(opts, "to");
     has_ipv4 = qemu_opt_get_bool(opts, "ipv4", false);
     has_ipv6 = qemu_opt_get_bool(opts, "ipv6", false);
-    display = g_strdup_printf("%s%s%s%s", vnc,
-                              has_to ? to : "",
-                              has_ipv4 ? ",ipv4" : "",
-                              has_ipv6 ? ",ipv6" : "");
+    if (has_to) {
+        qemu_opt_set(sopts, "to", has_to, &error_abort);
+        qemu_opt_set(wsopts, "to", has_to, &error_abort);
+    }
+    if (has_ipv4) {
+        qemu_opt_set(sopts, "ipv4", "on", &error_abort);
+        qemu_opt_set(wsopts, "ipv4", "on", &error_abort);
+    }
+    if (has_ipv6) {
+        qemu_opt_set(sopts, "ipv6", "on", &error_abort);
+        qemu_opt_set(wsopts, "ipv6", "on", &error_abort);
+    }
 
     password = qemu_opt_get_bool(opts, "password", false);
     if (password && fips_get_state()) {
@@ -3423,19 +3444,9 @@ void vnc_display_open(const char *id, Error **errp)
  #ifdef CONFIG_VNC_WS
     websocket = qemu_opt_get(opts, "websocket");
     if (websocket) {
-        /* extract the host specification from display */
-        char  *host = NULL, *host_end = NULL;
         vs->ws_enabled = true;
+        qemu_opt_set(wsopts, "port", websocket, &error_abort);
 
-        /* ipv6 hosts have colons */
-        host_end = strrchr(display, ':');
-        if (host_end) {
-            host = g_strndup(display, host_end - display + 1);
-        } else {
-            host = g_strdup(":");
-        }
-        ws_display = g_strconcat(host, websocket, NULL);
-        g_free(host);
     }
 #endif /* CONFIG_VNC_WS */
 
@@ -3605,10 +3616,10 @@ void vnc_display_open(const char *id, Error **errp)
 #ifdef CONFIG_VNC_WS
         vs->lwebsock = -1;
 #endif
-        if (strncmp(display, "unix:", 5) == 0) {
-            csock = unix_connect(display+5, errp);
+        if (strncmp(vnc, "unix:", 5) == 0) {
+            csock = unix_connect(vnc+5, errp);
         } else {
-            csock = inet_connect(display, errp);
+            csock = inet_connect(vnc, errp);
         }
         if (csock < 0) {
             goto fail;
@@ -3616,19 +3627,17 @@ void vnc_display_open(const char *id, Error **errp)
         vnc_connect(vs, csock, false, false);
     } else {
         /* listen for connects */
-        if (strncmp(display, "unix:", 5) == 0) {
-            vs->lsock = unix_listen(display+5, NULL, 0, errp);
+        if (strncmp(vnc, "unix:", 5) == 0) {
+            vs->lsock = unix_listen(vnc+5, NULL, 0, errp);
             vs->is_unix = true;
         } else {
-            vs->lsock = inet_listen(display, NULL, 0,
-                                    SOCK_STREAM, 5900, errp);
+            vs->lsock = inet_listen_opts(sopts, 5900, errp);
             if (vs->lsock < 0) {
                 goto fail;
             }
 #ifdef CONFIG_VNC_WS
             if (vs->ws_enabled) {
-                vs->lwebsock = inet_listen(ws_display, NULL, 0,
-                                           SOCK_STREAM, 0, errp);
+                vs->lwebsock = inet_listen_opts(wsopts, 0, errp);
                 if (vs->lwebsock < 0) {
                     if (vs->lsock) {
                         close(vs->lsock);
@@ -3639,27 +3648,25 @@ void vnc_display_open(const char *id, Error **errp)
             }
 #endif /* CONFIG_VNC_WS */
         }
-        g_free(to);
-        g_free(display);
         vs->enabled = true;
         qemu_set_fd_handler2(vs->lsock, NULL,
                 vnc_listen_regular_read, NULL, vs);
 #ifdef CONFIG_VNC_WS
-        g_free(ws_display);
         if (vs->ws_enabled) {
             qemu_set_fd_handler2(vs->lwebsock, NULL,
                     vnc_listen_websocket_read, NULL, vs);
         }
 #endif /* CONFIG_VNC_WS */
     }
+    qemu_opts_del(sopts);
+    qemu_opts_del(wsopts);
     return;
 
 fail:
-    g_free(to);
-    g_free(display);
+    qemu_opts_del(sopts);
+    qemu_opts_del(wsopts);
     vs->enabled = false;
 #ifdef CONFIG_VNC_WS
-    g_free(ws_display);
     vs->ws_enabled = false;
 #endif /* CONFIG_VNC_WS */
 }
Signature · 1 line
1.8.3.1
#6 lore raw

[Qemu-devel] [PULL 4/7] ui: fix regression in x509verify parameter for VNC server

In reply to Gerd Hoffmann

From: "Daniel P. Berrange" <[email protected]>

The 'x509verify' parameter is documented as taking a path to the x509 certificates, ie the same syntax as the 'x509' parameter.

commit 4db14629c38611061fc19ec6927405923de84f08
Author: Gerd Hoffmann <[email protected]>
Date: Tue Sep 16 12:33:03 2014 +0200

vnc: switch to QemuOpts, allow multiple servers

caused a regression by turning 'x509verify' into a boolean parameter instead. This breaks setup from libvirt and is not consistent with the docs.

---
 ui/vnc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
ui/vnc.c +7 -2
index db8409b..b514777 100644
@@ -3303,7 +3303,7 @@ static QemuOptsList qemu_vnc_opts = {
             .type = QEMU_OPT_BOOL,
         },{
             .name = "x509verify",
-            .type = QEMU_OPT_BOOL,
+            .type = QEMU_OPT_STRING,
         },{
             .name = "acl",
             .type = QEMU_OPT_BOOL,
@@ -3410,9 +3410,14 @@ void vnc_display_open(const char *id, Error **errp)
 #ifdef CONFIG_VNC_TLS
     tls  = qemu_opt_get_bool(opts, "tls", false);
     path = qemu_opt_get(opts, "x509");
+    if (!path) {
+        path = qemu_opt_get(opts, "x509verify");
+        if (path) {
+            vs->tls.x509verify = true;
+        }
+    }
     if (path) {
         x509 = true;
-        vs->tls.x509verify = qemu_opt_get_bool(opts, "x509verify", false);
         if (vnc_tls_set_x509_creds_dir(vs, path) < 0) {
             error_setg(errp, "Failed to find x509 certificates/keys in %s",
                        path);
Signature · 1 line
1.8.3.1
#7 lore raw

[Qemu-devel] [PULL 1/7] vnc: drop display+ws_display from VncDisplay

In reply to Gerd Hoffmann

Nobody cares about those strings, they are only used to check whenever the vnc server / websocket support is enabled or not. Add bools for this and drop the strings.

---
 ui/vnc-auth-sasl.c |  2 +-
 ui/vnc.c           | 54 +++++++++++++++++++++++-------------------------------
 ui/vnc.h           |  6 +++---
 3 files changed, 27 insertions(+), 35 deletions(-)
ui/vnc-auth-sasl.c +1 -1
index f3ad75d..2ddd259 100644
@@ -555,7 +555,7 @@ void start_auth_sasl(VncState *vs)
 
     memset (&secprops, 0, sizeof secprops);
     /* Inform SASL that we've got an external SSF layer from TLS */
-    if (strncmp(vs->vd->display, "unix:", 5) == 0
+    if (vs->vd->is_unix
 #ifdef CONFIG_VNC_TLS
         /* Disable SSF, if using TLS+x509+SASL only. TLS without x509
            is not sufficiently strong */
ui/vnc.c +23 -31

134 lines not on this page · raw message

ui/vnc.h +3 -3
index 5e2b1a5..66a0298 100644
@@ -158,8 +158,7 @@ struct VncDisplay
     int lsock;
 #ifdef CONFIG_VNC_WS
     int lwebsock;
-    bool websocket;
-    char *ws_display;
+    bool ws_enabled;
 #endif
     DisplaySurface *ds;
     DisplayChangeListener dcl;
@@ -176,7 +175,8 @@ struct VncDisplay
 
     const char *id;
     QTAILQ_ENTRY(VncDisplay) next;
-    char *display;
+    bool enabled;
+    bool is_unix;
     char *password;
     time_t expires;
     int auth;
Signature · 1 line
1.8.3.1
#8 lore raw
In reply to Gerd Hoffmann
Quoted 16 lines · Gerd Hoffmann

Hi,

Some vnc cleanups, more QemuOpts conversion fallout fixes.

please pull,
Gerd

The following changes since commit 9159eb9abc31e02797dc55998e71f12c06846d55:

Merge remote-tracking branch 'remotes/amit/tags/vser-for-2.3-1' into staging (2015-03-11 14:27:13 +0000)

are available in the git repository at:

git://git.kraxel.org/qemu tags/pull-vnc-20150312-1

Quoted 8 lines

for you to fetch changes up to 81607cbfa433272d1f09bd0f0ae6c3b14f818972:

vnc: fix segmentation fault when invalid vnc parameters are specified (2015-03-12 09:09:10 +0100)

----------------------------------------------------------------
vnc: bugfixes and cleanups.

----------------------------------------------------------------

Applied, thanks.

-- PMM