Skip to content

Commit f6b3a07

Browse files
authored
bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866)
Add missing terminated NUL in sockaddr_un's length - Linux: https://man7.org/linux/man-pages/man7/unix.7.html - *BSD: SUN_LEN
1 parent 58448cb commit f6b3a07

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add missing terminated NUL in sockaddr_un's length
2+
3+
This was potentially observable when using non-abstract AF_UNIX datagram sockets to processes written in another programming language.

Modules/socketmodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
16891689
"AF_UNIX path too long");
16901690
goto unix_out;
16911691
}
1692+
1693+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
16921694
}
16931695
else
16941696
#endif /* linux */
@@ -1700,10 +1702,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
17001702
goto unix_out;
17011703
}
17021704
addr->sun_path[path.len] = 0;
1705+
1706+
/* including the tailing NUL */
1707+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;
17031708
}
17041709
addr->sun_family = s->sock_family;
17051710
memcpy(addr->sun_path, path.buf, path.len);
1706-
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
1711+
17071712
retval = 1;
17081713
unix_out:
17091714
PyBuffer_Release(&path);

0 commit comments

Comments
 (0)