Quellcode durchsuchen

[pixbuf] Avoid potential division by zero

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>
tags/v1.20.1
Michael Brown vor 7 Jahren
Ursprung
Commit
966a960a83
1 geänderte Dateien mit 3 neuen und 1 gelöschten Zeilen
  1. 3
    1
      src/core/pixbuf.c

+ 3
- 1
src/core/pixbuf.c Datei anzeigen

68
 	pixbuf->len = ( width * height * sizeof ( uint32_t ) );
68
 	pixbuf->len = ( width * height * sizeof ( uint32_t ) );
69
 
69
 
70
 	/* Check for multiplication overflow */
70
 	/* Check for multiplication overflow */
71
-	if ( ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height )
71
+	if ( ( width != 0 ) &&
72
+	     ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) {
72
 		goto err_overflow;
73
 		goto err_overflow;
74
+	}
73
 
75
 
74
 	/* Allocate pixel data buffer */
76
 	/* Allocate pixel data buffer */
75
 	pixbuf->data = umalloc ( pixbuf->len );
77
 	pixbuf->data = umalloc ( pixbuf->len );

Laden…
Abbrechen
Speichern