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
This commit is contained in:
ty 2022-03-28 04:22:22 +08:00 committed by GitHub
parent 58448cbd96
commit f6b3a07b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -0,0 +1,3 @@
Add missing terminated NUL in sockaddr_un's length
This was potentially observable when using non-abstract AF_UNIX datagram sockets to processes written in another programming language.

View File

@ -1689,6 +1689,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
"AF_UNIX path too long");
goto unix_out;
}
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
}
else
#endif /* linux */
@ -1700,10 +1702,13 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
goto unix_out;
}
addr->sun_path[path.len] = 0;
/* including the tailing NUL */
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path) + 1;
}
addr->sun_family = s->sock_family;
memcpy(addr->sun_path, path.buf, path.len);
*len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
retval = 1;
unix_out:
PyBuffer_Release(&path);