Improvements for kore.recvmsg() in Python.

The cmsghdr contains a length (cmsg_len) which indicates the length
of the data in combination with the cmsghdr length itself.

Remove the length of the cmsghdr before passing it back up to callers
so they don't need to bother with it.

This also fixes a mistake where we ended up copying extra data
from the ancdata buffer that was unintended.
This commit is contained in:
Joris Vink 2022-04-22 17:01:06 +02:00
parent 5e47218ccd
commit f7a76f7e96
1 changed files with 5 additions and 2 deletions

View File

@ -898,6 +898,7 @@ static PyObject *
python_cmsg_to_list(struct msghdr *msg)
{
struct cmsghdr *c;
size_t len;
Py_ssize_t idx;
PyObject *list, *tuple;
@ -907,8 +908,10 @@ python_cmsg_to_list(struct msghdr *msg)
idx = 0;
for (c = CMSG_FIRSTHDR(msg); c != NULL; c = CMSG_NXTHDR(msg, c)) {
tuple = Py_BuildValue("(Iiiy#)", c->cmsg_len,
c->cmsg_level, c->cmsg_type, CMSG_DATA(c), c->cmsg_len);
len = c->cmsg_len - sizeof(*c);
tuple = Py_BuildValue("(Iiiy#)", len,
c->cmsg_level, c->cmsg_type, CMSG_DATA(c), len);
if (tuple == NULL) {
Py_DECREF(list);