summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie Zhao <zhaoyu_hit@qq.com>2022-10-30 04:34:46 (GMT)
committerGitHub <noreply@github.com>2022-10-30 04:34:46 (GMT)
commit3ac8c0ab6ee819a14b1c8e0992acbaf376a46058 (patch)
tree79d77067debcba2cbcbdb370d478e3faad05c136
parentfc94d55ff453a3101e4c00a394d4e38ae2fece13 (diff)
downloadcpython-3ac8c0ab6ee819a14b1c8e0992acbaf376a46058.zip
cpython-3ac8c0ab6ee819a14b1c8e0992acbaf376a46058.tar.gz
cpython-3ac8c0ab6ee819a14b1c8e0992acbaf376a46058.tar.bz2
gh-98793: Fix typecheck in `overlapped.c` (#98835)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py11
-rw-r--r--Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst1
-rw-r--r--Modules/clinic/overlapped.c.h10
-rw-r--r--Modules/overlapped.c8
4 files changed, 25 insertions, 5 deletions
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 6b4f65c..5033acc 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -239,6 +239,17 @@ class ProactorTests(test_utils.TestCase):
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
+ proactor = self.loop._proactor
+ sock = socket.socket(type=socket.SOCK_DGRAM)
+ bad_address = None
+ with self.assertRaises(TypeError):
+ proactor.connect(sock, bad_address)
+ with self.assertRaises(TypeError):
+ proactor.sendto(sock, b'abc', addr=bad_address)
+ sock.close()
+
class WinPolicyTests(test_utils.TestCase):
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 0000000..7b67af0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-10-29-03-40-18.gh-issue-98793.WSPB4A.rst
@@ -0,0 +1 @@
+Fix argument typechecks in :func:`!_overlapped.WSAConnect` and :func:`!_overlapped.Overlapped.WSASendTo` functions.
diff --git a/Modules/clinic/overlapped.c.h b/Modules/clinic/overlapped.c.h
index e8c2fe5..9d9f2cb 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 @@ exit:
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 369b1be..deb772e 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;