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 349300af08.
This commit is contained in:
Richard W.M. Jones
2013-04-16 19:33:54 +01:00
parent 87690b10ff
commit 44092e06ce

View File

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