mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 22:15:20 +00:00
virBitmapNewQuiet: Don't fail on unlikely overflow scenario
Modify the condition which would make virBitmapNewQuiet fail to possibly overallocate by 1 rather than failing. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
6d6480c462
commit
bbeab0479c
@ -55,8 +55,7 @@ struct _virBitmap {
|
|||||||
*
|
*
|
||||||
* Allocate a bitmap capable of containing @size bits.
|
* Allocate a bitmap capable of containing @size bits.
|
||||||
*
|
*
|
||||||
* Returns a pointer to the allocated bitmap or NULL if memory cannot be
|
* Returns a pointer to the allocated bitmap.
|
||||||
* allocated. Does not report libvirt errors.
|
|
||||||
*/
|
*/
|
||||||
virBitmapPtr
|
virBitmapPtr
|
||||||
virBitmapNewQuiet(size_t size)
|
virBitmapNewQuiet(size_t size)
|
||||||
@ -64,10 +63,13 @@ virBitmapNewQuiet(size_t size)
|
|||||||
virBitmapPtr bitmap;
|
virBitmapPtr bitmap;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size)
|
if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size) {
|
||||||
return NULL;
|
/* VIR_DIV_UP would overflow, let's overallocate by 1 entry instead of
|
||||||
|
* the potential overflow */
|
||||||
sz = VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT);
|
sz = (size / VIR_BITMAP_BITS_PER_UNIT) + 1;
|
||||||
|
} else {
|
||||||
|
sz = VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT);
|
||||||
|
}
|
||||||
|
|
||||||
bitmap = g_new0(virBitmap, 1);
|
bitmap = g_new0(virBitmap, 1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user