Merge pull request #31 from vibe-d/fix_winapi_watcher_destruction

Fix a possible range error when a win32 file watcher gets destroyed w…
This commit is contained in:
Sönke Ludwig 2017-11-17 23:07:59 +01:00 committed by GitHub
commit bcc6614b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,16 +77,24 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
{ {
import std.conv : to; import std.conv : to;
auto handle = overlapped.hEvent; // *file* handle
auto id = WatcherID(cast(int)handle);
auto slot = () @trusted { return &WinAPIEventDriver.threadInstance.core.m_handles[handle].watcher(); } ();
if (dwError != 0) { if (dwError != 0) {
// FIXME: this must be propagated to the caller // FIXME: this must be propagated to the caller
//logWarn("Failed to read directory changes: %s", dwError); //logWarn("Failed to read directory changes: %s", dwError);
return; return;
} }
auto handle = overlapped.hEvent; // *file* handle
auto id = WatcherID(cast(int)handle);
/* HACK: this avoids a range voilation in case an already destroyed
watcher still fires a completed event. It does not avoid problems
that may arise from reused file handles.
*/
if (handle !in WinAPIEventDriver.threadInstance.core.m_handles)
return;
auto slot = () @trusted { return &WinAPIEventDriver.threadInstance.core.m_handles[handle].watcher(); } ();
ubyte[] result = slot.buffer[0 .. cbTransferred]; ubyte[] result = slot.buffer[0 .. cbTransferred];
do { do {
assert(result.length >= FILE_NOTIFY_INFORMATION.sizeof); assert(result.length >= FILE_NOTIFY_INFORMATION.sizeof);