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:
Radek Smejkal 2023-02-14 02:37:34 +01:00 committed by GitHub
parent 0c6fe81dce
commit 928752ce4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 6 deletions

View file

@ -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;