8000 bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux by pitrou · Pull Request #1370 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4682,6 +4682,10 @@ def bind(self, sock, path):
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)
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ Extension Modules
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).

Expand Down
6 changes: 3 additions & 3 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
{
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 */
Expand Down
0