Do not crash so easily when given invalid uri

'remote-viewer foobar' shouldn't crash
This commit is contained in:
Marc-André Lureau 2012-03-16 13:17:09 +01:00
parent cf5082577a
commit e06c822023
3 changed files with 7 additions and 5 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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,16 +107,17 @@ 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