Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_asyncio/test_windows_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,25 @@ def test_popen(self):
pass


class OverlappedRefleakTests(unittest.TestCase):

def test_wsasendto_failure(self):
ov = _overlapped.Overlapped()
buf = bytearray(4096)
with self.assertRaises(OSError):
ov.WSASendTo(0x1234, buf, 0, ("127.0.0.1", 1))

def test_wsarecvfrom_failure(self):
ov = _overlapped.Overlapped()
with self.assertRaises(OSError):
ov.WSARecvFrom(0x1234, 1024, 0)

def test_wsarecvfrominto_failure(self):
ov = _overlapped.Overlapped()
buf = bytearray(4096)
with self.assertRaises(OSError):
ov.WSARecvFromInto(0x1234, buf, len(buf), 0)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix possible buffer leaks in Windows overlapped I/O on error handling.
6 changes: 3 additions & 3 deletions Modules/overlapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ _overlapped_Overlapped_WSASendTo_impl(OverlappedObject *self, HANDLE handle,
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
self->type = TYPE_NOT_STARTED;
Overlapped_clear(self);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was very confused with this, I thought it was tp_clear but it's explicitly not tp_clear so this looks like the correct fix.

return SetFromWindowsErr(err);
}
}
Expand Down Expand Up @@ -1873,7 +1873,7 @@ _overlapped_Overlapped_WSARecvFrom_impl(OverlappedObject *self,
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
self->type = TYPE_NOT_STARTED;
Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
Expand Down Expand Up @@ -1940,7 +1940,7 @@ _overlapped_Overlapped_WSARecvFromInto_impl(OverlappedObject *self,
case ERROR_IO_PENDING:
Py_RETURN_NONE;
default:
self->type = TYPE_NOT_STARTED;
Overlapped_clear(self);
return SetFromWindowsErr(err);
}
}
Expand Down
Loading