Commit b50af42b authored by GangCao's avatar GangCao Committed by Tomasz Zawadzki
Browse files

lib/virtio: return error if CMSG_FIRSTHDR returns NULL



Fix issue: potential NULL pointer dereference

Change-Id: I623096c49e7a75e66404666a2f502ba3209e3530
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14330


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarDong Yi <dongx.yi@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent 503835ee
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;