[dpdk-dev,3/3] vhost: fix potential NULL pointer dereference

Message ID 1467086311-13527-4-git-send-email-yuanhan.liu@linux.intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Commit Message

Yuanhan Liu June 28, 2016, 3:58 a.m. UTC
  Fix the potential NULL pointer dereference issue raised by Coverity.

    578             reconn = malloc(sizeof(*reconn));
    >>>     CID 127481:  Null pointer dereferences  (NULL_RETURNS)
    >>>     Dereferencing a null pointer "reconn".
    579             reconn->un = un;

Coverity issue: 127481
Fixes: e623e0c6d8a5 ("vhost: add reconnect ability")

Reported-by: John McNamara <john.mcnamara@intel.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost_user/vhost-net-user.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 67303a4..a0d83f3 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -577,6 +577,12 @@  vhost_user_create_client(struct vhost_user_socket *vsocket)
 
 	RTE_LOG(ERR, VHOST_CONFIG, "%s: reconnecting...\n", path);
 	reconn = malloc(sizeof(*reconn));
+	if (reconn == NULL) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"failed to allocate memory for reconnect\n");
+		close(fd);
+		return -1;
+	}
 	reconn->un = un;
 	reconn->fd = fd;
 	reconn->vsocket = vsocket;