diff mbox series

sockets: avoid crash when cleaning up sockets for an invalid FD

Message ID 20171027085633.14367-1-berrange@redhat.com
State New
Headers show
Series sockets: avoid crash when cleaning up sockets for an invalid FD | expand

Commit Message

Daniel P. Berrangé Oct. 27, 2017, 8:56 a.m. UTC
If socket_listen_cleanup is passed an invalid FD, then querying the socket
local address will fail. We must thus be prepared for the returned addr to
be NULL

Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 util/qemu-sockets.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Dr. David Alan Gilbert Oct. 27, 2017, 12:29 p.m. UTC | #1
* Daniel P. Berrange (berrange@redhat.com) wrote:
> If socket_listen_cleanup is passed an invalid FD, then querying the socket
> local address will fail. We must thus be prepared for the returned addr to
> be NULL
> 
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  util/qemu-sockets.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index b47fb45885..c7fdaa63fb 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -1073,6 +1073,9 @@ void socket_listen_cleanup(int fd, Error **errp)
>      SocketAddress *addr;
>  
>      addr = socket_local_address(fd, errp);
> +    if (!addr) {
> +        return;
> +    }
>  
>      if (addr->type == SOCKET_ADDRESS_TYPE_UNIX
>          && addr->u.q_unix.path) {
> -- 
> 2.13.6
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox series

Patch

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index b47fb45885..c7fdaa63fb 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -1073,6 +1073,9 @@  void socket_listen_cleanup(int fd, Error **errp)
     SocketAddress *addr;
 
     addr = socket_local_address(fd, errp);
+    if (!addr) {
+        return;
+    }
 
     if (addr->type == SOCKET_ADDRESS_TYPE_UNIX
         && addr->u.q_unix.path) {