Skip to contentSkip to conversation

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

PATCH In review Daniel P. Berrange 2 participants 2 messages Oct 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sockets: avoid crash when cleaning up sockets for an invalid FD

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

---
 util/qemu-sockets.c | 3 +++
 1 file changed, 3 insertions(+)
util/qemu-sockets.c +3 -0
index b47fb45885..c7fdaa63fb 100644
@@ -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) {
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · * Daniel P. Berrange ([email protected]) 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

Quoted 21 lines
---
 util/qemu-sockets.c | 3 +++
 1 file changed, 3 insertions(+)
util/qemu-sockets.c +3 -0
index b47fb45885..c7fdaa63fb 100644
@@ -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) {
Signature · 1 line
2.13.6

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK