summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-05-02 15:20:00 (GMT)
committerGitHub <noreply@github.com>2017-05-02 15:20:00 (GMT)
commit495b5021e73e3c4b6404417ecf4fa83aa10297f0 (patch)
tree74eebc9c19415d534342984ed3fe25f22a194f3e /Modules/socketmodule.c
parentb0d82036549074357717d130a772d1e2ebc8ea01 (diff)
downloadcpython-495b5021e73e3c4b6404417ecf4fa83aa10297f0.zip
cpython-495b5021e73e3c4b6404417ecf4fa83aa10297f0.tar.gz
cpython-495b5021e73e3c4b6404417ecf4fa83aa10297f0.tar.bz2
bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux (#1370)
* bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux * Add NEWS entry
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 6d5c256..456c664 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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 */