mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Close #13022: _multiprocessing.recvfd() doesn't check that file descriptor was actually received
This commit is contained in:
parent
d0b10a6435
commit
4507e6456e
3 changed files with 31 additions and 0 deletions
|
@ -177,6 +177,17 @@ multiprocessing_recvfd(PyObject *self, PyObject *args)
|
|||
if (res < 0)
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
|
||||
if (msg.msg_controllen < CMSG_LEN(sizeof(int)) ||
|
||||
(cmsg = CMSG_FIRSTHDR(&msg)) == NULL ||
|
||||
cmsg->cmsg_level != SOL_SOCKET ||
|
||||
cmsg->cmsg_type != SCM_RIGHTS ||
|
||||
cmsg->cmsg_len < CMSG_LEN(sizeof(int))) {
|
||||
/* If at least one control message is present, there should be
|
||||
no room for any further data in the buffer. */
|
||||
PyErr_SetString(PyExc_RuntimeError, "No file descriptor received");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = * (int *) CMSG_DATA(cmsg);
|
||||
return Py_BuildValue("i", fd);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue