Backport bpo-30205 to 3.5 (#1404) · python/cpython@0d9d618 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4589,6 +4589,10 @@ def bind(self, sock, path): | ||
4589 | 4589 | else: |
4590 | 4590 | raise |
4591 | 4591 | |
4592 | +def testUnbound(self): | |
4593 | +# Issue #30205 | |
4594 | +self.assertIn(self.sock.getsockname(), (None, '')) | |
4595 | + | |
4592 | 4596 | def testStrAddr(self): |
4593 | 4597 | # Test binding to and retrieving a normal string pathname. |
4594 | 4598 | path = os.path.abspath(support.TESTFN) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -49,6 +49,8 @@ Extension Modules | ||
49 | 49 | Library |
50 | 50 | ------- |
51 | 51 | |
52 | +- bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux. | |
53 | + | |
52 | 54 | - bpo-30070: Fixed leaks and crashes in errors handling in the parser module. |
53 | 55 | |
54 | 56 | - bpo-30061: Fixed crashes in IOBase methods __next__() and readlines() when |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1183,9 +1183,9 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) | ||
1183 | 1183 | { |
1184 | 1184 | struct sockaddr_un *a = (struct sockaddr_un *) addr; |
1185 | 1185 | #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); | |
1189 | 1189 | } |
1190 | 1190 | else |
1191 | 1191 | #endif /* linux */ |