]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remote: Avoid crash in remoteSplitURIScheme()
authorAndrea Bolognani <abologna@redhat.com>
Fri, 10 Dec 2021 09:54:54 +0000 (10:54 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 10 Dec 2021 13:15:23 +0000 (14:15 +0100)
We need to make sure the URI scheme is present before passing
it to strchr(), otherwise we're going to get

  $ virt-ssh-helper foo
  Segmentation fault (core dumped)

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/remote/remote_sockets.c

index 2979576680e8983a05a4150d73323e41b488e5c3..c315b24d30bcb0a6185c9ffd8c3c61e780c8c381 100644 (file)
@@ -69,7 +69,15 @@ remoteSplitURIScheme(virURI *uri,
                      char **driver,
                      remoteDriverTransport *transport)
 {
-    char *p = strchr(uri->scheme, '+');
+    char *p = NULL;
+
+    if (!uri->scheme) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing scheme for URI"));
+        return -1;
+    }
+
+    p = strchr(uri->scheme, '+');
 
     if (p)
         *driver = g_strndup(uri->scheme, p - uri->scheme);