Skip to content

Commit 0c2ff08

Browse files
authored
Backport bpo-30205 to 3.6 (#1403)
1 parent 4dae0d1 commit 0c2ff08

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
@@ -4660,6 +4660,10 @@ def bind(self, sock, path):
46604660
else:
46614661
raise
46624662

4663+
def testUnbound(self):
4664+
# Issue #30205
4665+
self.assertIn(self.sock.getsockname(), ('', None))
4666+
46634667
def testStrAddr(self):
46644668
# Test binding to and retrieving a normal string pathname.
46654669
path = os.path.abspath(support.TESTFN)

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux.
40+
3941
- bpo-30070: Fixed leaks and crashes in errors handling in the parser module.
4042

4143
- 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
@@ -1212,9 +1212,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
12121212
{
12131213
struct sockaddr_un *a = (struct sockaddr_un *) addr;
12141214
#ifdef __linux__
1215-
if (a->sun_path[0] == 0) { /* Linux abstract namespace */
1216-
addrlen -= offsetof(struct sockaddr_un, sun_path);
1217-
return PyBytes_FromStringAndSize(a->sun_path, addrlen);
1215+
size_t linuxaddrlen = addrlen - offsetof(struct sockaddr_un, sun_path);
1216+
if (linuxaddrlen > 0 && a->sun_path[0] == 0) { /* Linux abstract namespace */
1217+
return PyBytes_FromStringAndSize(a->sun_path, linuxaddrlen);
12181218
}
12191219
else
12201220
#endif /* linux */

0 commit comments

Comments
 (0)