Skip to content

Commit 0d9d618

Browse files
authored
Backport bpo-30205 to 3.5 (#1404)
1 parent 360fb81 commit 0d9d618

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Lib/test/test_socket.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4589,6 +4589,10 @@ def bind(self, sock, path):
45894589
else:
45904590
raise
45914591

4592+
def testUnbound(self):
4593+
# Issue #30205
4594+
self.assertIn(self.sock.getsockname(), (None, ''))
4595+
45924596
def testStrAddr(self):
45934597
# Test binding to and retrieving a normal string pathname.
45944598
path = os.path.abspath(support.TESTFN)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Extension Modules
4949
Library
5050
-------
5151

52+
- bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux.
53+
5254
- bpo-30070: Fixed leaks and crashes in errors handling in the parser module.
5355

5456
- bpo-30061: Fixed crashes in IOBase methods __next__() and readlines() when

Modules/socketmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
11831183
{
11841184
struct sockaddr_un *a = (struct sockaddr_un *) addr;
11851185
#ifdef linux
1186-
if (a->sun_path[0] == 0) { /* Linux abstract namespace */
1187-
addrlen -= offsetof(struct sockaddr_un, sun_path);
1188-
return PyBytes_FromStringAndSize(a->sun_path, addrlen);
1186+
size_t linuxaddrlen = addrlen - offsetof(struct sockaddr_un, sun_path);
1187+
if (linuxaddrlen > 0 && a->sun_path[0] == 0) { /* Linux abstract namespace */
1188+
return PyBytes_FromStringAndSize(a->sun_path, linuxaddrlen);
11891189
}
11901190
else
11911191
#endif /* linux */

0 commit comments

Comments
 (0)