]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[malloc] Sanity check parameters to alloc_memblock() and free_memblock()
authorMichael Brown <mcb30@ipxe.org>
Mon, 15 Dec 2014 14:42:26 +0000 (14:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 15 Dec 2014 14:42:26 +0000 (14:42 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/malloc.c

index 42658128a2c9836b070b8c7af67368fab8fd015e..0993bdac75b41e73d8b47da79081c1e6b27c9185 100644 (file)
@@ -237,6 +237,10 @@ void * alloc_memblock ( size_t size, size_t align, size_t offset ) {
        struct memory_block *post;
        struct memory_block *ptr;
 
+       /* Sanity checks */
+       assert ( size != 0 );
+       assert ( ( align == 0 ) || ( ( align & ( align - 1 ) ) == 0 ) );
+
        valgrind_make_blocks_defined();
 
        /* Round up size to multiple of MIN_MEMBLOCK_SIZE and
@@ -338,6 +342,7 @@ void free_memblock ( void *ptr, size_t size ) {
        /* Round up size to match actual size that alloc_memblock()
         * would have used.
         */
+       assert ( size != 0 );
        size = ( size + MIN_MEMBLOCK_SIZE - 1 ) & ~( MIN_MEMBLOCK_SIZE - 1 );
        freeing = ptr;
        VALGRIND_MAKE_MEM_DEFINED ( freeing, sizeof ( *freeing ) );
@@ -444,6 +449,7 @@ void * realloc ( void *old_ptr, size_t new_size ) {
                                           data );
                VALGRIND_MAKE_MEM_DEFINED ( old_block, offsetof ( struct autosized_block, data ) );
                old_total_size = old_block->size;
+               assert ( old_total_size != 0 );
                old_size = ( old_total_size -
                             offsetof ( struct autosized_block, data ) );
                memcpy ( new_ptr, old_ptr,