mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
This commit is contained in:
parent
6b45b1ee52
commit
06b1d21e7d
2 changed files with 18 additions and 6 deletions
|
@ -90,6 +90,20 @@ if hasattr(socket, 'getservbyname'):
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
# On some versions, this loses a reference
|
||||||
|
import sys
|
||||||
|
orig = sys.getrefcount(__name__)
|
||||||
|
socket.getnameinfo(__name__,0)
|
||||||
|
except SystemError:
|
||||||
|
if sys.getrefcount(__name__) <> orig:
|
||||||
|
raise TestFailed,"socket.getnameinfo loses a reference"
|
||||||
|
|
||||||
|
try:
|
||||||
|
# On some versions, this crashes the interpreter.
|
||||||
|
socket.getnameinfo(('x', 0, 0, 0), 0)
|
||||||
|
except socket.gaierror:
|
||||||
|
pass
|
||||||
|
|
||||||
canfork = hasattr(os, 'fork')
|
canfork = hasattr(os, 'fork')
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2537,18 +2537,17 @@ PySocket_getnameinfo(PyObject *self, PyObject *args)
|
||||||
PyObject *sa = (PyObject *)NULL;
|
PyObject *sa = (PyObject *)NULL;
|
||||||
int flags;
|
int flags;
|
||||||
char *hostp;
|
char *hostp;
|
||||||
int n, port, flowinfo, scope_id;
|
int port, flowinfo, scope_id;
|
||||||
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
|
char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
|
||||||
struct addrinfo hints, *res = NULL;
|
struct addrinfo hints, *res = NULL;
|
||||||
int error;
|
int error;
|
||||||
PyObject *ret = (PyObject *)NULL;
|
PyObject *ret = (PyObject *)NULL;
|
||||||
|
|
||||||
flags = flowinfo = scope_id = 0;
|
flags = flowinfo = scope_id = 0;
|
||||||
if (PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags) == 0)
|
if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
|
||||||
|
return NULL;
|
||||||
|
if (!PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, &scope_id))
|
||||||
return NULL;
|
return NULL;
|
||||||
n = PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, scope_id);
|
|
||||||
if (n == 0)
|
|
||||||
goto fail;
|
|
||||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
|
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = PF_UNSPEC;
|
hints.ai_family = PF_UNSPEC;
|
||||||
|
@ -2597,7 +2596,6 @@ PySocket_getnameinfo(PyObject *self, PyObject *args)
|
||||||
fail:
|
fail:
|
||||||
if (res)
|
if (res)
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
Py_XDECREF(sa);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue