kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit f7a76f7e9618516fc054f18e3e8011fa06356ae9
parent 5e47218ccd80d735d6b9254d5651bf23d0c4c17d
Author: Joris Vink <joris@coders.se>
Date:   Fri, 22 Apr 2022 17:01:06 +0200

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.

Diffstat:
src/python.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/python.c b/src/python.c @@ -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);