diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2017-12-22 11:08:49 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2018-03-13 18:06:06 +0000 |
commit | 30bdb3c56ddd911ab2b1629faa4ce6e883b80e2a (patch) | |
tree | 1d16d017837d0f101626771ca2c1c47180c78cce /util | |
parent | 58dc31f1a7dc6cd0f21bd51a34011ba366d36e53 (diff) | |
download | qemu-30bdb3c56ddd911ab2b1629faa4ce6e883b80e2a.zip qemu-30bdb3c56ddd911ab2b1629faa4ce6e883b80e2a.tar.gz qemu-30bdb3c56ddd911ab2b1629faa4ce6e883b80e2a.tar.bz2 |
sockets: check that the named file descriptor is a socket
The SocketAddress struct has an "fd" type, which references the name of a
file descriptor passed over the monitor using the "getfd" command. We
currently blindly assume the FD is a socket, which can lead to hard to
diagnose errors later. This adds an explicit check that the FD is actually
a socket to improve the error diagnosis.
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/qemu-sockets.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index fa79471..6dc4613 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1042,6 +1042,20 @@ fail: return NULL; } +static int socket_get_fd(const char *fdstr, Error **errp) +{ + int fd = monitor_get_fd(cur_mon, fdstr, errp); + if (fd < 0) { + return -1; + } + if (!fd_is_socket(fd)) { + error_setg(errp, "File descriptor '%s' is not a socket", fdstr); + close(fd); + return -1; + } + return fd; +} + int socket_connect(SocketAddress *addr, Error **errp) { int fd; @@ -1056,7 +1070,7 @@ int socket_connect(SocketAddress *addr, Error **errp) break; case SOCKET_ADDRESS_TYPE_FD: - fd = monitor_get_fd(cur_mon, addr->u.fd.str, errp); + fd = socket_get_fd(addr->u.fd.str, errp); break; case SOCKET_ADDRESS_TYPE_VSOCK: @@ -1083,7 +1097,7 @@ int socket_listen(SocketAddress *addr, Error **errp) break; case SOCKET_ADDRESS_TYPE_FD: - fd = monitor_get_fd(cur_mon, addr->u.fd.str, errp); + fd = socket_get_fd(addr->u.fd.str, errp); break; case SOCKET_ADDRESS_TYPE_VSOCK: |