Skip to content

Commit 798eaca

Browse files
ambvCharlieZhao95kumaraditya303encukou
authored
[3.9] gh-98793: Fix typecheck in overlapped.c (GH-98835) (GH-98890) (GH-140825)
(cherry picked from commit d3d1738) Co-authored-by: Charlie Zhao <zhaoyu_hit@qq.com> Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 42762bb commit 798eaca

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Lib/test/test_asyncio/test_windows_events.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ def threadMain():
279279
stop.set()
280280
thr.join()
281281

282+
def test_address_argument_type_error(self):
283+
# Regression test for https://github.com/python/cpython/issues/98793
284+
proactor = self.loop._proactor
285+
sock = socket.socket(type=socket.SOCK_DGRAM)
286+
bad_address = None
287+
with self.assertRaises(TypeError):
288+
proactor.connect(sock, bad_address)
289+
with self.assertRaises(TypeError):
290+
proactor.sendto(sock, b'abc', addr=bad_address)
291+
sock.close()
292+
282293

283294
class WinPolicyTests(WindowsEventsTestCase):
284295

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix argument typechecks in :func:`!_overlapped.WSAConnect` and :func:`!_overlapped.Overlapped.WSASendTo` functions.

Modules/overlapped.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,9 @@ overlapped_WSAConnect(PyObject *self, PyObject *args)
15521552
int Length;
15531553
int err;
15541554

1555-
if (!PyArg_ParseTuple(args, F_HANDLE "O", &ConnectSocket, &AddressObj)) {
1555+
1556+
if (!PyArg_ParseTuple(args, F_HANDLE "O!:WSAConnect",
1557+
&ConnectSocket, &PyTuple_Type, &AddressObj)) {
15561558
return NULL;
15571559
}
15581560

@@ -1598,8 +1600,8 @@ Overlapped_WSASendTo(OverlappedObject *self, PyObject *args)
15981600
int ret;
15991601
DWORD err;
16001602

1601-
if (!PyArg_ParseTuple(args, F_HANDLE "O" F_DWORD "O",
1602-
&handle, &bufobj, &flags, &AddressObj))
1603+
if (!PyArg_ParseTuple(args, F_HANDLE "OkO!:WSASendTo",
1604+
&handle, &bufobj, &flags, &PyTuple_Type, &AddressObj))
16031605
{
16041606
return NULL;
16051607
}

0 commit comments

Comments
 (0)