Add NULL check for cmsg in receive_fd to prevent segfault

This commit is contained in:
Antonio SJ Musumeci 2026-03-10 10:58:01 -05:00
parent b768ba8ce1
commit cc67e791bf

View file

@ -259,11 +259,20 @@ static int receive_fd(int fd)
}
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg->cmsg_type != SCM_RIGHTS) {
fprintf(stderr, "got control message of unknown type %d\n",
cmsg->cmsg_type);
return -1;
}
if(!cmsg)
{
fprintf(stderr,"no control message received or not enough buf space\n");
return -1;
}
if(cmsg->cmsg_type != SCM_RIGHTS)
{
fprintf(stderr,
"got control message of unknown type %d\n",
cmsg->cmsg_type);
return -1;
}
return *(int*)CMSG_DATA(cmsg);
}