Skip to content

Commit f073cff

Browse files
committed
gh-84808: Handle errors returned by internal_connect()
internal_connect() errors when returning -1 with exception set. reported and proposed by Ryan C. Gordon
1 parent d9efa45 commit f073cff

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Modules/socketmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,7 @@ sock_connect_impl(PySocketSockObject *s, void* Py_UNUSED(data))
34053405
return 1;
34063406
}
34073407

3408+
/* Returns 0 on success, -1 with exception set on failure, or error code if not. */
34083409
static int
34093410
internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
34103411
int raise)
@@ -3489,7 +3490,7 @@ sock_connect(PySocketSockObject *s, PyObject *addro)
34893490
}
34903491

34913492
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, 1);
3492-
if (res < 0)
3493+
if (res == -1 && PyErr_Occurred())
34933494
return NULL;
34943495

34953496
Py_RETURN_NONE;
@@ -3520,7 +3521,7 @@ sock_connect_ex(PySocketSockObject *s, PyObject *addro)
35203521
}
35213522

35223523
res = internal_connect(s, SAS2SA(&addrbuf), addrlen, 0);
3523-
if (res < 0)
3524+
if (res == -1 && PyErr_Occurred())
35243525
return NULL;
35253526

35263527
return PyLong_FromLong((long) res);

0 commit comments

Comments
 (0)