Commit 9ce8e380 authored by Guido van Rossum's avatar Guido van Rossum

Fix two bugs in socket_getaddr():

(a) 'single' shouldn't be DECREF'ed in the cleanup code;
(b) the fallback case in makesockaddr() should use y# instead of s#
    in the format, since the data is bytes, not UTF-8 text.
parent 6ca130d0
...@@ -1174,8 +1174,8 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) ...@@ -1174,8 +1174,8 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
default: default:
/* If we don't know the address family, don't raise an /* If we don't know the address family, don't raise an
exception -- return it as a tuple. */ exception -- return it as an (int, bytes) tuple. */
return Py_BuildValue("is#", return Py_BuildValue("iy#",
addr->sa_family, addr->sa_family,
addr->sa_data, addr->sa_data,
sizeof(addr->sa_data)); sizeof(addr->sa_data));
...@@ -3743,7 +3743,6 @@ socket_getaddrinfo(PyObject *self, PyObject *args) ...@@ -3743,7 +3743,6 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
int family, socktype, protocol, flags; int family, socktype, protocol, flags;
int error; int error;
PyObject *all = (PyObject *)NULL; PyObject *all = (PyObject *)NULL;
PyObject *single = (PyObject *)NULL;
PyObject *idna = NULL; PyObject *idna = NULL;
family = socktype = protocol = flags = 0; family = socktype = protocol = flags = 0;
...@@ -3797,6 +3796,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args) ...@@ -3797,6 +3796,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
if ((all = PyList_New(0)) == NULL) if ((all = PyList_New(0)) == NULL)
goto err; goto err;
for (res = res0; res; res = res->ai_next) { for (res = res0; res; res = res->ai_next) {
PyObject *single;
PyObject *addr = PyObject *addr =
makesockaddr(-1, res->ai_addr, res->ai_addrlen, protocol); makesockaddr(-1, res->ai_addr, res->ai_addrlen, protocol);
if (addr == NULL) if (addr == NULL)
...@@ -3818,7 +3818,6 @@ socket_getaddrinfo(PyObject *self, PyObject *args) ...@@ -3818,7 +3818,6 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
freeaddrinfo(res0); freeaddrinfo(res0);
return all; return all;
err: err:
Py_XDECREF(single);
Py_XDECREF(all); Py_XDECREF(all);
Py_XDECREF(idna); Py_XDECREF(idna);
if (res0) if (res0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment