diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1745,8 +1745,11 @@ static const size_t cmsg_len_end = (offsetof(struct cmsghdr, cmsg_len) + sizeof(cmsgh->cmsg_len)); - /* Note that POSIX allows msg_controllen to be of signed type. */ - if (cmsgh == NULL || msg->msg_control == NULL || msg->msg_controllen < 0) + /* Note that POSIX in recent versions allows msg_controllen to be a signed + type fitting in 2**31-1, but older versions it says it should be + unsigned and fit within 2**32-1. */ + if (cmsgh == NULL || msg->msg_control == NULL || + ((long long)msg->msg_controllen) < 0) return 0; if (space < cmsg_len_end) space = cmsg_len_end;