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>
This commit is contained in:
Halil Pasic 2017-03-02 19:13:08 +01:00 committed by Michael S. Tsirkin
parent df90463632
commit aa26292859
2 changed files with 3 additions and 0 deletions

View 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)

View 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)