aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorHalil Pasic <pasic@linux.vnet.ibm.com>2017-03-02 19:13:08 +0100
committerMichael S. Tsirkin <mst@redhat.com>2017-03-29 02:35:23 +0300
commitaa262928595d431bfee7914cb7d9d79197f887a2 (patch)
tree8dfbad003754d9e9707f272609c656c248ab842a /util
parentdf9046363220e57d45818312759b954c033c58ab (diff)
event_notifier: prevent accidental use after close
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>
Diffstat (limited to 'util')
-rw-r--r--util/event_notifier-posix.c2
-rw-r--r--util/event_notifier-win32.c1
2 files changed, 3 insertions, 0 deletions
diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c
index 7e40252ade..acdbe3b483 100644
--- a/util/event_notifier-posix.c
+++ b/util/event_notifier-posix.c
@@ -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)
diff --git a/util/event_notifier-win32.c b/util/event_notifier-win32.c
index 519fb59123..62c53b0a99 100644
--- a/util/event_notifier-win32.c
+++ b/util/event_notifier-win32.c
@@ -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)