Skip to content

Commit dae09c2

Browse files
[3.9] bpo-44493: Add missing terminated NUL in sockaddr_un's length (GH-26866) (GH-32140) (GH-32156)
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 (cherry picked from commit 5944807) Co-authored-by: Miss Islington (bot) <[email protected]>
1 parent 1e3132b commit dae09c2

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
@@ -1722,6 +1722,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
17221722
"AF_UNIX path too long");
17231723
goto unix_out;
17241724
}
1725+
1726+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
17251727
}
17261728
else
17271729
#endif /* linux */
@@ -1733,10 +1735,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
17331735
goto unix_out;
17341736
}
17351737
addr->sun_path[path.len] = 0;
1738+
1739+
/* including the tailing NUL */
1740+
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;
17361741
}
17371742
addr->sun_family = s->sock_family;
17381743
memcpy(addr->sun_path, path.buf, path.len);
1739-
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
1744+
17401745
retval = 1;
17411746
unix_out:
17421747
PyBuffer_Release(&path);

0 commit comments

Comments
 (0)