diff options
author | Michael Brown | 2017-03-22 13:11:19 +0100 |
---|---|---|
committer | Michael Brown | 2017-03-22 13:11:19 +0100 |
commit | 966a960a8333a9d75da8103cbe5903d380ef7770 (patch) | |
tree | d7187ce48c9a815e33f1d5957146ec60462c38a9 /src/core | |
parent | [ath] Add missing break statements (diff) | |
download | ipxe-966a960a8333a9d75da8103cbe5903d380ef7770.tar.gz ipxe-966a960a8333a9d75da8103cbe5903d380ef7770.tar.xz ipxe-966a960a8333a9d75da8103cbe5903d380ef7770.zip |
[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>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/pixbuf.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/core/pixbuf.c b/src/core/pixbuf.c index 4742d285..641a0fb5 100644 --- a/src/core/pixbuf.c +++ b/src/core/pixbuf.c @@ -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 ); |