Commit 495b5021 authored by Antoine Pitrou's avatar Antoine Pitrou Committed by GitHub

bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux (#1370)

* bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux

* Add NEWS entry
parent b0d82036
...@@ -4682,6 +4682,10 @@ class TestUnixDomain(unittest.TestCase): ...@@ -4682,6 +4682,10 @@ class TestUnixDomain(unittest.TestCase):
else: else:
raise raise
def testUnbound(self):
# Issue #30205
self.assertEqual(self.sock.getsockname(), '')
def testStrAddr(self): def testStrAddr(self):
# Test binding to and retrieving a normal string pathname. # Test binding to and retrieving a normal string pathname.
path = os.path.abspath(support.TESTFN) path = os.path.abspath(support.TESTFN)
......
...@@ -317,6 +317,8 @@ Extension Modules ...@@ -317,6 +317,8 @@ Extension Modules
Library Library
------- -------
- bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux.
- bpo-30228: The seek() and tell() methods of io.FileIO now set the internal - bpo-30228: The seek() and tell() methods of io.FileIO now set the internal
seekable attribute to avoid one syscall on open() (in buffered or text mode). seekable attribute to avoid one syscall on open() (in buffered or text mode).
......
...@@ -1211,9 +1211,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) ...@@ -1211,9 +1211,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
{ {
struct sockaddr_un *a = (struct sockaddr_un *) addr; struct sockaddr_un *a = (struct sockaddr_un *) addr;
#ifdef __linux__ #ifdef __linux__
if (a->sun_path[0] == 0) { /* Linux abstract namespace */ size_t linuxaddrlen = addrlen - offsetof(struct sockaddr_un, sun_path);
addrlen -= offsetof(struct sockaddr_un, sun_path); if (linuxaddrlen > 0 && a->sun_path[0] == 0) { /* Linux abstract namespace */
return PyBytes_FromStringAndSize(a->sun_path, addrlen); return PyBytes_FromStringAndSize(a->sun_path, linuxaddrlen);
} }
else else
#endif /* linux */ #endif /* linux */
......
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