aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2015-03-12 10:35:53 +0000
committerPeter Maydell <peter.maydell@linaro.org>2015-03-12 10:35:54 +0000
commit2a5b58e2405e9fe42ba356b5a1b78146a4e9a659 (patch)
tree980eb554703193fb2bb47bacd81a7e38e6097bf1
parenta195fdd028370faa54ba3d627f1add8401ac5193 (diff)
parent81607cbfa433272d1f09bd0f0ae6c3b14f818972 (diff)
downloadqemu-2a5b58e2405e9fe42ba356b5a1b78146a4e9a659.zip
qemu-2a5b58e2405e9fe42ba356b5a1b78146a4e9a659.tar.gz
qemu-2a5b58e2405e9fe42ba356b5a1b78146a4e9a659.tar.bz2
Merge remote-tracking branch 'remotes/kraxel/tags/pull-vnc-20150312-1' into staging
vnc: bugfixes and cleanups. # gpg: Signature made Thu Mar 12 08:58:39 2015 GMT using RSA key ID D3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" * remotes/kraxel/tags/pull-vnc-20150312-1: vnc: fix segmentation fault when invalid vnc parameters are specified vnc: avoid possible file handler leak ui/console: fix OVERFLOW_BEFORE_WIDEN ui: fix regression in x509verify parameter for VNC server vnc: switch to inet_listen_opts vnc: remove dead code vnc: drop display+ws_display from VncDisplay Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--ui/console.c4
-rw-r--r--ui/vnc-auth-sasl.c2
-rw-r--r--ui/vnc.c128
-rw-r--r--ui/vnc.h6
4 files changed, 72 insertions, 68 deletions
diff --git a/ui/console.c b/ui/console.c
index 87af6b5..b15ca87 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -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;
}
diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c
index f3ad75d..2ddd259 100644
--- a/ui/vnc-auth-sasl.c
+++ b/ui/vnc-auth-sasl.c
@@ -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 */
diff --git a/ui/vnc.c b/ui/vnc.c
index ff0b5bd..6f9b718 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -407,7 +407,7 @@ VncInfo *qmp_query_vnc(Error **errp)
VncInfo *info = g_malloc0(sizeof(*info));
VncDisplay *vd = vnc_display_find(NULL);
- if (vd == NULL || vd->display == NULL) {
+ if (vd == NULL || !vd->enabled) {
info->enabled = false;
} else {
struct sockaddr_storage sa;
@@ -3190,16 +3190,15 @@ static void vnc_display_close(VncDisplay *vs)
{
if (!vs)
return;
- g_free(vs->display);
- vs->display = NULL;
+ vs->enabled = false;
+ vs->is_unix = false;
if (vs->lsock != -1) {
qemu_set_fd_handler2(vs->lsock, NULL, NULL, NULL, NULL);
close(vs->lsock);
vs->lsock = -1;
}
#ifdef CONFIG_VNC_WS
- g_free(vs->ws_display);
- vs->ws_display = NULL;
+ vs->ws_enabled = false;
if (vs->lwebsock != -1) {
qemu_set_fd_handler2(vs->lwebsock, NULL, NULL, NULL, NULL);
close(vs->lwebsock);
@@ -3304,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,
@@ -3323,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, *to = NULL;
+ char *h;
bool has_ipv4 = false;
bool has_ipv6 = false;
#ifdef CONFIG_VNC_WS
@@ -3362,17 +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" : "");
- vs->display = g_strdup(display);
+ 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()) {
@@ -3391,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);
@@ -3425,19 +3449,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->websocket = 1;
+ 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(":");
- }
- vs->ws_display = g_strconcat(host, websocket, NULL);
- g_free(host);
}
#endif /* CONFIG_VNC_WS */
@@ -3607,10 +3621,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;
@@ -3618,62 +3632,47 @@ void vnc_display_open(const char *id, Error **errp)
vnc_connect(vs, csock, false, false);
} else {
/* listen for connects */
- char *dpy;
- dpy = g_malloc(256);
- if (strncmp(display, "unix:", 5) == 0) {
- pstrcpy(dpy, 256, "unix:");
- vs->lsock = unix_listen(display+5, dpy+5, 256-5, 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, dpy, 256,
- SOCK_STREAM, 5900, errp);
+ vs->lsock = inet_listen_opts(sopts, 5900, errp);
if (vs->lsock < 0) {
- g_free(dpy);
goto fail;
}
#ifdef CONFIG_VNC_WS
- if (vs->websocket) {
- if (vs->ws_display) {
- vs->lwebsock = inet_listen(vs->ws_display, NULL, 256,
- SOCK_STREAM, 0, errp);
- } else {
- vs->lwebsock = inet_listen(vs->display, NULL, 256,
- SOCK_STREAM, 5700, 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;
}
- g_free(dpy);
goto fail;
}
}
#endif /* CONFIG_VNC_WS */
}
- g_free(to);
- g_free(display);
- g_free(vs->display);
- vs->display = dpy;
+ vs->enabled = true;
qemu_set_fd_handler2(vs->lsock, NULL,
vnc_listen_regular_read, NULL, vs);
#ifdef CONFIG_VNC_WS
- if (vs->websocket) {
+ 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);
- g_free(vs->display);
- vs->display = NULL;
+ qemu_opts_del(sopts);
+ qemu_opts_del(wsopts);
+ vs->enabled = false;
#ifdef CONFIG_VNC_WS
- g_free(vs->ws_display);
- vs->ws_display = NULL;
+ vs->ws_enabled = false;
#endif /* CONFIG_VNC_WS */
}
@@ -3704,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);
diff --git a/ui/vnc.h b/ui/vnc.h
index 5e2b1a5..66a0298 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -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;