[Libguestfs] [PATCH nbdkit v2] common/bitmap: Don't fail on realloc (ptr, 0)

Eric Blake eblake at redhat.com
Mon Sep 16 14:58:35 UTC 2019


On 9/15/19 6:55 AM, Richard W.M. Jones wrote:
> The following commands:
> 
>   nbdkit -fv --filter=cow memory size=512 --run 'qemu-img info $nbd'
>   nbdkit -fv --filter=cache memory size=512 --run 'qemu-img info $nbd'
>   nbdkit -fv --filter=cow null --run 'qemu-img info $nbd'
> 
> all fail with:
> 
>   nbdkit: memory[1]: error: realloc: Success

> This commit changes the code so it doesn't bother to call realloc if
> the new bitmap size would be 0.

ACK

> 
> There are many other places in nbdkit where we call realloc, and I did
> not vet any of them to see if similar bugs could be present, but it is
> quite likely.

I did an audit of them; you caught the only culprit:

common/include/get-current-dir-name.h - immune (used +1)
common/regions/regions.c - immune (used +1)
common/sparse/sparse.c - immune (used +1)
filters/readahead/readahead.c - immune (called with non-zero count)
plugins/floppy/directory-lfn.c - immune (used +1)
plugins/floppy/virtual-floppy.c - immune (used +1)
plugins/iso/iso.c - immune (used +1)
plugins/partitioning/partitioning.c - immune (used +1)
plugins/sh/call.c - immune (called with non-zero bufalloc)
plugins/split/split.c - immune (used +1)
plugins/ssh/ssh.c - immune (used +1)
server/extents.c - immune (called with non-zero new_extents)
server/sockets.c - immune (called with non-zero nr_socks)
server/threadlocal.c - immune (called with non-zero count)
tests/test-layers.c - immune (called with non-zero allocated)
wrapper.c - immune (used +1)


> 
> Note in passing that the correct way to use the cow/cache filter with
> a disk which isn't a multiple of the block size is to combine it with
> the truncate filter, eg:
> 
>   nbdkit -fv --filter=cow --filter=truncate memory size=512 round-up=4096
> 
> Thanks: Eric Blake
> ---


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190916/e0c464bd/attachment.sig>


More information about the Libguestfs mailing list