summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-05-02 22:14:29 (GMT)
committerGitHub <noreply@github.com>2017-05-02 22:14:29 (GMT)
commit0c2ff0898db2db9cd9c643dfadbff11761bacf5f (patch)
tree088ce426f1f31178b6a3e1c7f1db78b3074c9bb3
parent4dae0d111dd7bb34ec730eea2327a3219acff211 (diff)
downloadcpython-0c2ff0898db2db9cd9c643dfadbff11761bacf5f.zip
cpython-0c2ff0898db2db9cd9c643dfadbff11761bacf5f.tar.gz
cpython-0c2ff0898db2db9cd9c643dfadbff11761bacf5f.tar.bz2
Backport bpo-30205 to 3.6 (#1403)
-rw-r--r--Lib/test/test_socket.py4
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/socketmodule.c6
3 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 2497e47..80dfc40 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -4660,6 +4660,10 @@ class TestUnixDomain(unittest.TestCase):
else:
raise
+ def testUnbound(self):
+ # Issue #30205
+ self.assertIn(self.sock.getsockname(), ('', None))
+
def testStrAddr(self):
# Test binding to and retrieving a normal string pathname.
path = os.path.abspath(support.TESTFN)
diff --git a/Misc/NEWS b/Misc/NEWS
index 936e2b0..3b61543 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@ Core and Builtins
Library
-------
+- bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux.
+
- bpo-30070: Fixed leaks and crashes in errors handling in the parser module.
- bpo-30061: Fixed crashes in IOBase methods __next__() and readlines() when
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index f3654c9..42aec59 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1212,9 +1212,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 */