[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build |
Date: |
Fri, 28 Jul 2017 07:43:59 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
On 07/28/2017 07:31 AM, Olaf Hering wrote:
> g_malloc0_n is available since glib-2.24. To allow build with older glib
> versions use the generic g_malloc0, which is already used in many other
> places in the code.
>
> Fixes commit 3284fad728 ("xen-disk: add support for multi-page shared rings")
>
> Signed-off-by: Olaf Hering <address@hidden>
> ---
> hw/block/xen_disk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
> index d42ed7070d..71deec17b0 100644
> --- a/hw/block/xen_disk.c
> +++ b/hw/block/xen_disk.c
> @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev)
> return -1;
> }
>
> - domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
> + domids = g_malloc0(blkdev->nr_ring_ref * sizeof(uint32_t));
This version is prone to multiplication overflow (well, maybe not, but
you have to audit for that). Wouldn't it be better to use:
domids = g_new0(blkdev->nr_ring_ref, uint32_t)
which preserves the safety of g_malloc0_n?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature