remote: Avoid crash in remoteSplitURIScheme()

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>
This commit is contained in:
Andrea Bolognani 2021-12-10 10:54:54 +01:00
parent 3179220e4f
commit 2bdd654269

View 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);