DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: yuanhan.liu@linux.intel.com, john.mcnamara@intel.com,
	Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH] net/virtio-user: check value returned from malloc
Date: Thu, 26 Jan 2017 03:05:42 +0000	[thread overview]
Message-ID: <1485399942-94705-1-git-send-email-jianfeng.tan@intel.com> (raw)

Value returned from malloc is not checked for errors before being used.
This patch fixes following coverity issue.

    static struct vhost_memory_kernel *
    prepare_vhost_memory_kernel(void)
    {
        ...
        vm = malloc(sizeof(struct vhost_memory_kernel) +
                    max_regions *
                    sizeof(struct vhost_memory_region));
        ...
    >>>     CID 140744:    (NULL_RETURNS)
    >>>     Dereferencing a null pointer "vm".
                mr = &vm->regions[k++];

Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost")
Coverity issue: 140744

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c
index 9b6637d..05aa6c6 100644
--- a/drivers/net/virtio/virtio_user/vhost_kernel.c
+++ b/drivers/net/virtio/virtio_user/vhost_kernel.c
@@ -114,6 +114,8 @@ prepare_vhost_memory_kernel(void)
 	vm = malloc(sizeof(struct vhost_memory_kernel) +
 		    max_regions *
 		    sizeof(struct vhost_memory_region));
+	if (!vm)
+		return NULL;
 
 	for (i = 0; i < RTE_MAX_MEMSEG; ++i) {
 		seg = &rte_eal_get_configuration()->mem_config->memseg[i];
-- 
2.7.4

             reply	other threads:[~2017-01-26  3:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26  3:05 Jianfeng Tan [this message]
2017-01-28 13:26 ` Yuanhan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1485399942-94705-1-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).