]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-143249: Fix buffer leak when overlapped operation fails to start on windows...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Jan 2026 13:53:41 +0000 (14:53 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Jan 2026 13:53:41 +0000 (13:53 +0000)
gh-143249: Fix buffer leak when overlapped operation fails to start on windows (GH-143250)
(cherry picked from commit 103a384bfdeafc68ab39ea9bf8838a8b2eec83dd)

Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Lib/test/test_asyncio/test_windows_utils.py
Misc/NEWS.d/next/Library/2025-12-28-14-41-02.gh-issue-143249.K4vEp4.rst [new file with mode: 0644]
Modules/overlapped.c

index eafa5be38296822551e2b5a6033216b617bdb3a6..c84edacfbd57903242bbb26b7d25b72a7e0d2227 100644 (file)
@@ -129,5 +129,25 @@ class PopenTests(unittest.TestCase):
             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()
diff --git a/Misc/NEWS.d/next/Library/2025-12-28-14-41-02.gh-issue-143249.K4vEp4.rst b/Misc/NEWS.d/next/Library/2025-12-28-14-41-02.gh-issue-143249.K4vEp4.rst
new file mode 100644 (file)
index 0000000..d50d9e3
--- /dev/null
@@ -0,0 +1 @@
+Fix possible buffer leaks in Windows overlapped I/O on error handling.
index 77ee70ae133c858586460ec920b6ca96950f8238..567593e05c4c11147c036879901724535880a106 100644 (file)
@@ -1794,7 +1794,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);
             return SetFromWindowsErr(err);
     }
 }
@@ -1868,7 +1868,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);
     }
 }
@@ -1935,7 +1935,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);
     }
 }