lib/virtio: return error if CMSG_FIRSTHDR returns NULL

Fix issue: potential NULL pointer dereference

Change-Id: I623096c49e7a75e66404666a2f502ba3209e3530
Signed-off-by: GangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14330
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
GangCao 2022-09-01 21:52:21 -04:00 committed by Tomasz Zawadzki
parent 503835ee63
commit b50af42b62

View File

@ -58,6 +58,10 @@ vhost_user_write(int fd, void *buf, int len, int *fds, int fd_num)
msgh.msg_control = control;
msgh.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&msgh);
if (!cmsg) {
SPDK_WARNLOG("First HDR is NULL\n");
return -EIO;
}
cmsg->cmsg_len = CMSG_LEN(fd_size);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;