[virt-tools-list] [PATCH virt-viewer] Do not crash so easily when given invalid uri

Marc-André Lureau marcandre.lureau at gmail.com
Fri Mar 16 12:17:22 UTC 2012


'remote-viewer foobar' shouldn't crash
---
 src/remote-viewer.c    |    2 +-
 src/virt-viewer-app.c  |    1 +
 src/virt-viewer-util.c |   10 ++++++----
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index f4932c1..f0512c8 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -730,7 +730,7 @@ remote_viewer_start(VirtViewerApp *app)
         DEBUG_LOG("Opening display to %s", guri);
         g_object_set(app, "title", guri, NULL);
 
-        if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0) {
+        if (virt_viewer_util_extract_host(guri, &type, NULL, NULL, NULL, NULL) < 0 || type == NULL) {
             virt_viewer_app_simple_message_dialog(app, _("Cannot determine the connection type from URI"));
             goto cleanup;
         }
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index fc22721..789cb88 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -669,6 +669,7 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type)
     g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), -1);
     VirtViewerAppPrivate *priv = self->priv;
     g_return_val_if_fail(priv->session == NULL, -1);
+    g_return_val_if_fail(type != NULL, -1);
 
 #ifdef HAVE_GTK_VNC
     if (g_ascii_strcasecmp(type, "vnc") == 0) {
diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
index dbb0bce..fe838af 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -81,7 +81,7 @@ virt_viewer_util_extract_host(const char *uristr,
                               int *port)
 {
     xmlURIPtr uri;
-    char *offset;
+    char *offset = NULL;
 
     if (uristr == NULL ||
         !g_ascii_strcasecmp(uristr, "xen"))
@@ -107,20 +107,22 @@ virt_viewer_util_extract_host(const char *uristr,
     if (port)
         *port = uri->port;
 
-    offset = strchr(uri->scheme, '+');
+    if (uri->scheme)
+        offset = strchr(uri->scheme, '+');
 
     if (transport) {
         if (offset)
-            *transport = g_strdup(offset+1);
+            *transport = g_strdup(offset + 1);
         else
             *transport = NULL;
     }
 
-    if (scheme) {
+    if (scheme && uri->scheme) {
         if (offset)
             *scheme = g_strndup(uri->scheme, offset - uri->scheme);
         else
             *scheme = g_strdup(uri->scheme);
+
     }
 
     xmlFreeURI(uri);
-- 
1.7.7.6




More information about the virt-tools-list mailing list