* bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux
* Add NEWS entry
else:
raise
+ def testUnbound(self):
+ # Issue #30205
+ self.assertEqual(self.sock.getsockname(), '')
+
def testStrAddr(self):
# Test binding to and retrieving a normal string pathname.
path = os.path.abspath(support.TESTFN)
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
seekable attribute to avoid one syscall on open() (in buffered or text mode).
{
struct sockaddr_un *a = (struct sockaddr_un *) addr;
#ifdef __linux__
- if (a->sun_path[0] == 0) { /* Linux abstract namespace */
- addrlen -= offsetof(struct sockaddr_un, sun_path);
- return PyBytes_FromStringAndSize(a->sun_path, addrlen);
+ size_t linuxaddrlen = addrlen - offsetof(struct sockaddr_un, sun_path);
+ if (linuxaddrlen > 0 && a->sun_path[0] == 0) { /* Linux abstract namespace */
+ return PyBytes_FromStringAndSize(a->sun_path, linuxaddrlen);
}
else
#endif /* linux */