mirror of
https://github.com/python/cpython.git
synced 2025-09-03 15:31:08 +00:00
gh-74895: getaddrinfo no longer raises OverflowError (#2435)
`socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
This commit is contained in:
parent
0c6fe81dce
commit
928752ce4c
5 changed files with 68 additions and 6 deletions
|
@ -6650,7 +6650,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
|
|||
struct addrinfo *res0 = NULL;
|
||||
PyObject *hobj = NULL;
|
||||
PyObject *pobj = (PyObject *)NULL;
|
||||
char pbuf[30];
|
||||
PyObject *pstr = NULL;
|
||||
const char *hptr, *pptr;
|
||||
int family, socktype, protocol, flags;
|
||||
int error;
|
||||
|
@ -6680,11 +6680,13 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
|
|||
return NULL;
|
||||
}
|
||||
if (PyLong_CheckExact(pobj)) {
|
||||
long value = PyLong_AsLong(pobj);
|
||||
if (value == -1 && PyErr_Occurred())
|
||||
pstr = PyObject_Str(pobj);
|
||||
if (pstr == NULL)
|
||||
goto err;
|
||||
assert(PyUnicode_Check(pstr));
|
||||
pptr = PyUnicode_AsUTF8(pstr);
|
||||
if (pptr == NULL)
|
||||
goto err;
|
||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
|
||||
pptr = pbuf;
|
||||
} else if (PyUnicode_Check(pobj)) {
|
||||
pptr = PyUnicode_AsUTF8(pobj);
|
||||
if (pptr == NULL)
|
||||
|
@ -6750,12 +6752,14 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
|
|||
Py_DECREF(single);
|
||||
}
|
||||
Py_XDECREF(idna);
|
||||
Py_XDECREF(pstr);
|
||||
if (res0)
|
||||
freeaddrinfo(res0);
|
||||
return all;
|
||||
err:
|
||||
Py_XDECREF(all);
|
||||
Py_XDECREF(idna);
|
||||
Py_XDECREF(pstr);
|
||||
if (res0)
|
||||
freeaddrinfo(res0);
|
||||
return (PyObject *)NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue