From 97787c4714e9b587e7f5c0a1e2ff955db4e4fdc7 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Sat, 29 Oct 2022 09:46:18 +0800 Subject: [PATCH 1/6] Add Argument Clinic in overlapped --- Modules/clinic/overlapped.c.h | 10 +++++++++- Modules/overlapped.c | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Modules/clinic/overlapped.c.h b/Modules/clinic/overlapped.c.h index e8c2fe5653d10d..9d9f2cbf6afdc2 100644 --- a/Modules/clinic/overlapped.c.h +++ b/Modules/clinic/overlapped.c.h @@ -1093,6 +1093,10 @@ _overlapped_WSAConnect(PyObject *module, PyObject *const *args, Py_ssize_t nargs if (!ConnectSocket && PyErr_Occurred()) { goto exit; } + if (!PyTuple_Check(args[1])) { + _PyArg_BadArgument("WSAConnect", "argument 2", "tuple", args[1]); + goto exit; + } AddressObj = args[1]; return_value = _overlapped_WSAConnect_impl(module, ConnectSocket, AddressObj); @@ -1140,6 +1144,10 @@ _overlapped_Overlapped_WSASendTo(OverlappedObject *self, PyObject *const *args, if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { goto exit; } + if (!PyTuple_Check(args[3])) { + _PyArg_BadArgument("WSASendTo", "argument 4", "tuple", args[3]); + goto exit; + } AddressObj = args[3]; return_value = _overlapped_Overlapped_WSASendTo_impl(self, handle, &bufobj, flags, AddressObj); @@ -1254,4 +1262,4 @@ _overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const * return return_value; } -/*[clinic end generated code: output=e0f866222bd5873b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b2e89694b8de3d00 input=a9049054013a1b77]*/ diff --git a/Modules/overlapped.c b/Modules/overlapped.c index 369b1beae84e3f..deb772e9eff487 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -1674,7 +1674,7 @@ Overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg) _overlapped.WSAConnect client_handle as ConnectSocket: HANDLE - address_as_bytes as AddressObj: object + address_as_bytes as AddressObj: object(subclass_of='&PyTuple_Type') / Bind a remote address to a connectionless (UDP) socket. @@ -1683,7 +1683,7 @@ Bind a remote address to a connectionless (UDP) socket. static PyObject * _overlapped_WSAConnect_impl(PyObject *module, HANDLE ConnectSocket, PyObject *AddressObj) -/*[clinic end generated code: output=ea0b4391e94dad63 input=169f8075e9ae7fa4]*/ +/*[clinic end generated code: output=ea0b4391e94dad63 input=7cf65313d49c015a]*/ { char AddressBuf[sizeof(struct sockaddr_in6)]; SOCKADDR *Address = (SOCKADDR*)AddressBuf; @@ -1717,7 +1717,7 @@ _overlapped.Overlapped.WSASendTo handle: HANDLE buf as bufobj: Py_buffer flags: DWORD - address_as_bytes as AddressObj: object + address_as_bytes as AddressObj: object(subclass_of='&PyTuple_Type') / Start overlapped sendto over a connectionless (UDP) socket. @@ -1727,7 +1727,7 @@ static PyObject * _overlapped_Overlapped_WSASendTo_impl(OverlappedObject *self, HANDLE handle, Py_buffer *bufobj, DWORD flags, PyObject *AddressObj) -/*[clinic end generated code: output=3cdedc4cfaeb70cd input=b7c1749a62e2e374]*/ +/*[clinic end generated code: output=3cdedc4cfaeb70cd input=31f44cd4ab92fc33]*/ { char AddressBuf[sizeof(struct sockaddr_in6)]; SOCKADDR *Address = (SOCKADDR*)AddressBuf; From 0e9bd1c6e001926fa0b47aeb118ddec506ed11e4 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Sat, 29 Oct 2022 11:15:31 +0800 Subject: [PATCH 2/6] Add test for TypeError --- Lib/test/test_asyncio/test_windows_events.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index 6b4f65c3376f5d..3245a0bd7ee045 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -239,6 +239,16 @@ def test_read_self_pipe_restart(self): self.close_loop(self.loop) self.assertFalse(self.loop.call_exception_handler.called) + def test_address_argument_type_error(self): + # Regression test for https://github.com/python/cpython/issues/98793 + ip = asyncio.windows_events.IocpProactor() + sock = socket.socket(type=socket.SOCK_DGRAM) + bad_address = None + with self.assertRaises(TypeError): + ip.connect(sock, bad_address) + with self.assertRaises(TypeError): + ip.sendto(sock, b'abc', addr=bad_address) + class WinPolicyTests(test_utils.TestCase): From 1de857c60e55b05e75baba757de11f24852aacf8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 29 Oct 2022 03:40:19 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst diff --git a/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst new file mode 100644 index 00000000000000..f5bcb6084390b4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst @@ -0,0 +1 @@ +Fixes typecheck in :func:`_overlapped.WSAConnect` and :func:`_overlapped.Overlapped.WSASendTo`. From 6ff30962318a6e61e94bb02698d0fc61dd4d95b4 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Sat, 29 Oct 2022 17:10:35 +0800 Subject: [PATCH 4/6] fix failed test --- Lib/test/test_asyncio/test_windows_events.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index 3245a0bd7ee045..5033acc052486b 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -241,13 +241,14 @@ def test_read_self_pipe_restart(self): def test_address_argument_type_error(self): # Regression test for https://github.com/python/cpython/issues/98793 - ip = asyncio.windows_events.IocpProactor() + proactor = self.loop._proactor sock = socket.socket(type=socket.SOCK_DGRAM) bad_address = None with self.assertRaises(TypeError): - ip.connect(sock, bad_address) + proactor.connect(sock, bad_address) with self.assertRaises(TypeError): - ip.sendto(sock, b'abc', addr=bad_address) + proactor.sendto(sock, b'abc', addr=bad_address) + sock.close() class WinPolicyTests(test_utils.TestCase): From a6f893a6c0e51aa0dee5afa362c7b73f4f87c4b7 Mon Sep 17 00:00:00 2001 From: Charlie Zhao Date: Sat, 29 Oct 2022 18:08:06 +0800 Subject: [PATCH 5/6] Update Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- .../next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst index f5bcb6084390b4..662f825cc8dc04 100644 --- a/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst +++ b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst @@ -1 +1 @@ -Fixes typecheck in :func:`_overlapped.WSAConnect` and :func:`_overlapped.Overlapped.WSASendTo`. +Fix argument typechecks in :func:`!_overlapped.WSAConnect` and :func:`!_overlapped.Overlapped.WSASendTo` functions. From 40dc5addb6ce3b3aee1fae8b2560df14eb9ea4c1 Mon Sep 17 00:00:00 2001 From: CharlieZhao Date: Sat, 29 Oct 2022 18:22:39 +0800 Subject: [PATCH 6/6] Delete trailing whitespace --- .../next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst index 662f825cc8dc04..7b67af06cf3d17 100644 --- a/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst +++ b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst @@ -1 +1 @@ -Fix argument typechecks in :func:`!_overlapped.WSAConnect` and :func:`!_overlapped.Overlapped.WSASendTo` functions. +Fix argument typechecks in :func:`!_overlapped.WSAConnect` and :func:`!_overlapped.Overlapped.WSASendTo` functions.