]> git.proxmox.com Git - mirror_qemu.git/commitdiff
event_notifier: prevent accidental use after close
authorHalil Pasic <pasic@linux.vnet.ibm.com>
Thu, 2 Mar 2017 18:13:08 +0000 (19:13 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 28 Mar 2017 23:35:23 +0000 (02:35 +0300)
Let's set the handles to the underlying facilities to their extremal
value so no accidental misuse can happen, and to make it obvious that the
notifier is dysfunctional. E.g. if we just close an fd but do not touch
the int holding the fd eventually a read/write could succeed again when
the fd gets reused, and corrupt the file addressed by the fd.

Signed-off-by: Halil Pasic <pasic@linux.vnet.ibm.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
util/event_notifier-posix.c
util/event_notifier-win32.c

index 7e40252ade44936352f5d7e13b5de2fb089f70ae..acdbe3b4832d47ad25084c82fc7266282e446417 100644 (file)
@@ -81,8 +81,10 @@ void event_notifier_cleanup(EventNotifier *e)
 {
     if (e->rfd != e->wfd) {
         close(e->rfd);
+        e->rfd = -1;
     }
     close(e->wfd);
+    e->wfd = -1;
 }
 
 int event_notifier_get_fd(const EventNotifier *e)
index 519fb59123f3c8f840a3ecb7221f6e7ca3a3e405..62c53b0a9909af504281c5e55f749a22eff899fb 100644 (file)
@@ -25,6 +25,7 @@ int event_notifier_init(EventNotifier *e, int active)
 void event_notifier_cleanup(EventNotifier *e)
 {
     CloseHandle(e->event);
+    e->event = NULL;
 }
 
 HANDLE event_notifier_get_handle(EventNotifier *e)