]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[pixbuf] Avoid potential division by zero
authorMichael Brown <mcb30@ipxe.org>
Wed, 22 Mar 2017 12:11:19 +0000 (14:11 +0200)
committerMichael Brown <mcb30@ipxe.org>
Wed, 22 Mar 2017 12:11:19 +0000 (14:11 +0200)
Avoid potential division by zero when performing the check against
multiplication overflow.  (Note that if the width is zero then there
can be no overflow anyway, so it is then safe to bypass the check.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/pixbuf.c

index 4742d285dd44a5a6a37ca8ebf589579bfe13bfad..641a0fb53f096ea00b34d56440023dec3ebbc509 100644 (file)
@@ -68,8 +68,10 @@ struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
        pixbuf->len = ( width * height * sizeof ( uint32_t ) );
 
        /* Check for multiplication overflow */
-       if ( ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height )
+       if ( ( width != 0 ) &&
+            ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) {
                goto err_overflow;
+       }
 
        /* Allocate pixel data buffer */
        pixbuf->data = umalloc ( pixbuf->len );