From 44092e06ce459dce1be5658bba2c8cf4dd438d54 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 16 Apr 2013 19:33:54 +0100 Subject: [PATCH] fish: options: Format server name as "tcp:host[:port]". This is safer, because otherwise a URI could contain some clever "unix:..." string as the hostname, tricking qemu into opening a Unix domain socket at an uncontrolled location. This fixes commit 349300af08be9ae9f3d7259e688e2ee5318f2171. --- fish/options.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fish/options.c b/fish/options.c index cfeeadd44..3fcb74eda 100644 --- a/fish/options.c +++ b/fish/options.c @@ -125,17 +125,16 @@ static char ** make_server (xmlURIPtr uri) { char **ret; - char *host_port; + char *server; if (uri->port == 0) { - host_port = strdup (uri->server); - if (host_port == NULL) { - perror ("strdup"); + if (asprintf (&server, "tcp:%s", uri->server) == -1) { + perror ("asprintf"); exit (EXIT_FAILURE); } } else { - if (asprintf (&host_port, "%s:%d", uri->server, uri->port) == -1) { + if (asprintf (&server, "tcp:%s:%d", uri->server, uri->port) == -1) { perror ("asprintf"); exit (EXIT_FAILURE); } @@ -145,7 +144,7 @@ make_server (xmlURIPtr uri) * only a singleton is passed by us. */ ret = malloc (sizeof (char *) * 2); - ret[0] = host_port; + ret[0] = server; ret[1] = NULL; return ret;