Skip to content

Commit 5944807

Browse files
[3.10] bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866) (GH-32140)
Add missing terminated NUL in sockaddr_un's length - Linux: https://man7.org/linux/man-pages/man7/unix.7.html - *BSD: SUN_LEN (cherry picked from commit f6b3a07) Co-authored-by: ty <[email protected]> Automerge-Triggered-By: GH:gpshead
1 parent 9194a7b commit 5944807

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
@@ -1680,6 +1680,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
16801680
"AF_UNIX path too long");
16811681
goto unix_out;
16821682
}
1683+
1684+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
16831685
}
16841686
else
16851687
#endif /* linux */
@@ -1691,10 +1693,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
16911693
goto unix_out;
16921694
}
16931695
addr->sun_path[path.len] = 0;
1696+
1697+
/* including the tailing NUL */
1698+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;
16941699
}
16951700
addr->sun_family = s->sock_family;
16961701
memcpy(addr->sun_path, path.buf, path.len);
1697-
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
1702+
16981703
retval = 1;
16991704
unix_out:
17001705
PyBuffer_Release(&path);

0 commit comments

Comments
 (0)