* [dpdk-dev] [PATCH] net/virtio-user: check value returned from malloc
@ 2017-01-26 3:05 Jianfeng Tan
2017-01-28 13:26 ` Yuanhan Liu
0 siblings, 1 reply; 2+ messages in thread
From: Jianfeng Tan @ 2017-01-26 3:05 UTC (permalink / raw)
To: dev; +Cc: yuanhan.liu, john.mcnamara, Jianfeng Tan
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [dpdk-dev] [PATCH] net/virtio-user: check value returned from malloc
2017-01-26 3:05 [dpdk-dev] [PATCH] net/virtio-user: check value returned from malloc Jianfeng Tan
@ 2017-01-28 13:26 ` Yuanhan Liu
0 siblings, 0 replies; 2+ messages in thread
From: Yuanhan Liu @ 2017-01-28 13:26 UTC (permalink / raw)
To: Jianfeng Tan; +Cc: dev, john.mcnamara
On Thu, Jan 26, 2017 at 03:05:42AM +0000, Jianfeng Tan wrote:
> 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>
Applied to dpdk-next-virtio.
--yliu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-28 13:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 3:05 [dpdk-dev] [PATCH] net/virtio-user: check value returned from malloc Jianfeng Tan
2017-01-28 13:26 ` Yuanhan Liu
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).