aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2015-07-22 14:27:47 +0100
committerJeff Cody <jcody@redhat.com>2015-07-28 00:19:05 -0400
commit325e3904210c779a13fbbc9ee156056d045d7eee (patch)
treecd8ca0e70fd61319b87bf874d95079fcfb24bd68
parent6a55c82cece217ab99ed95a412fa7ddf5d5f257b (diff)
block/ssh: Avoid segfault if inet_connect doesn't set errno.
On some (but not all) systems: $ qemu-img create -f qcow2 overlay -b ssh://xen/ Segmentation fault It turns out this happens when inet_connect returns -1 in the following code, but errno == 0. s->sock = inet_connect(s->hostport, errp); if (s->sock < 0) { ret = -errno; goto err; } In the test case above, no host called "xen" exists, so getaddrinfo fails. On Fedora 22, getaddrinfo happens to set errno = ENOENT (although it is *not* documented to do that), so it doesn't segfault. On RHEL 7, errno is not set by the failing getaddrinfo, so ret = -errno = 0, so the caller doesn't know there was an error and continues with a half-initialized BDRVSSHState struct, and everything goes south from there, eventually resulting in a segfault. Fix this by setting ret to -EIO (same as block/nbd.c and block/sheepdog.c). The real error is saved in the Error** errp struct, so it is printed correctly: $ ./qemu-img create -f qcow2 overlay -b ssh://xen/ qemu-img: overlay: address resolution failed for xen:22: No address associated with hostname Signed-off-by: Richard W.M. Jones <rjones@redhat.com> Reported-by: Jun Li BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1147343 Signed-off-by: Jeff Cody <jcody@redhat.com>
-rw-r--r--block/ssh.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/block/ssh.c b/block/ssh.c
index aebb18cc8f..8d0673903d 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -563,7 +563,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
/* Open the socket and connect. */
s->sock = inet_connect(s->hostport, errp);
if (s->sock < 0) {
- ret = -errno;
+ ret = -EIO;
goto err;
}