From e06c822023ac2f5d2b2dae50dd813f4a0d5e908b Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 16 Mar 2012 13:17:09 +0100 Subject: Do not crash so easily when given invalid uri 'remote-viewer foobar' shouldn't crash --- src/virt-viewer-util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/virt-viewer-util.c') diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index dbb0bce..e4a0cc4 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,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 -- cgit