mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 12:00:19 +03:00
[pixbuf] Check for unsigned integer overflow on multiplication
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -65,6 +65,10 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
|
|||||||
pixbuf->height = height;
|
pixbuf->height = height;
|
||||||
pixbuf->len = ( width * height * sizeof ( uint32_t ) );
|
pixbuf->len = ( width * height * sizeof ( uint32_t ) );
|
||||||
|
|
||||||
|
/* Check for multiplication overflow */
|
||||||
|
if ( ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height )
|
||||||
|
goto err_overflow;
|
||||||
|
|
||||||
/* Allocate pixel data buffer */
|
/* Allocate pixel data buffer */
|
||||||
pixbuf->data = umalloc ( pixbuf->len );
|
pixbuf->data = umalloc ( pixbuf->len );
|
||||||
if ( ! pixbuf->data )
|
if ( ! pixbuf->data )
|
||||||
@@ -73,6 +77,7 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
|
|||||||
return pixbuf;
|
return pixbuf;
|
||||||
|
|
||||||
err_alloc_data:
|
err_alloc_data:
|
||||||
|
err_overflow:
|
||||||
pixbuf_put ( pixbuf );
|
pixbuf_put ( pixbuf );
|
||||||
err_alloc_pixbuf:
|
err_alloc_pixbuf:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user