]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Three uses of makesockaddr() used sockaddr buffers that had not be cleared;
authorFred Drake <fdrake@acm.org>
Wed, 9 May 2001 19:11:33 +0000 (19:11 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 9 May 2001 19:11:33 +0000 (19:11 +0000)
this could cause invalid paths to be returned for AF_UNIX sockets on some
platforms (including FreeBSD 4.2-RELEASE), appearantly because there is
no assurance that the address will be nul-terminated when filled in by the
kernel.

PySocketSock_recvfrom():  Use PyString_AS_STRING() to get the data pointer
    of a string we create ourselves; there is no need for the extra type
    check from PyString_AsString().

This closes SF bug #416573.

Modules/socketmodule.c

index ce572ff4f4e82c1e9b15ff4f326a0a700252d987..7e14743a893974b21c5aad749def92f93a7f0a1d 100644 (file)
@@ -790,6 +790,7 @@ PySocketSock_accept(PySocketSockObject *s, PyObject *args)
                return NULL;
        if (!getsockaddrlen(s, &addrlen))
                return NULL;
+       memset(addrbuf, 0, addrlen);
        Py_BEGIN_ALLOW_THREADS
        newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
        Py_END_ALLOW_THREADS
@@ -1212,6 +1213,7 @@ PySocketSock_getpeername(PySocketSockObject *s, PyObject *args)
                return NULL;
        if (!getsockaddrlen(s, &addrlen))
                return NULL;
+       memset(addrbuf, 0, addrlen);
        Py_BEGIN_ALLOW_THREADS
        res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
        Py_END_ALLOW_THREADS
@@ -1360,7 +1362,8 @@ PySocketSock_recvfrom(PySocketSockObject *s, PyObject *args)
        if (buf == NULL)
                return NULL;
        Py_BEGIN_ALLOW_THREADS
-       n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
+       memset(addrbuf, 0, addrlen);
+       n = recvfrom(s->sock_fd, PyString_AS_STRING(buf), len, flags,
 #ifndef MS_WINDOWS
 #if defined(PYOS_OS2)
                     (struct sockaddr *)addrbuf, &addrlen