egl: Restrict multiplication in calloc arguments to use compile-time constants
authorCarl Worth <cworth@cworth.org>
Wed, 3 Sep 2014 21:33:18 +0000 (14:33 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 4 Sep 2014 01:37:02 +0000 (18:37 -0700)
As explained in the previous commit, we want to avoid the possibility of
integer-multiplication overflow while allocating buffers.

In these two cases, the final allocation size is the product of three values:
one variable and two that are fixed constants at compile time.

In this commit, we move the explicit multiplication to involve only the
compile-time constants, preventing any overflow from that multiplication, (and
allowing calloc to catch any potential overflow from the remainining implicit
multiplication).

Reviewed-by: Matt Turner <mattst88@gmail.com>
src/egl/drivers/dri2/platform_drm.c
src/egl/drivers/dri2/platform_wayland.c

index e272beb943efc230d6819c65d5cfb3bafa761a6f..70bd7d4827c2f8a77e58b2f0ba4d01e0e84b0d6b 100644 (file)
@@ -352,7 +352,7 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable,
    const unsigned int format = 32;
    int i;
 
-   attachments_with_format = calloc(count * 2, sizeof(unsigned int));
+   attachments_with_format = calloc(count, 2 * sizeof(unsigned int));
    if (!attachments_with_format) {
       *out_count = 0;
       return NULL;
index 537d26e97b797bab7b92b8cbb8382c2c4adfb487..59b27922056be51abdc16cbce935fb93b1814a4d 100644 (file)
@@ -468,7 +468,7 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable,
    const unsigned int format = 32;
    int i;
 
-   attachments_with_format = calloc(count * 2, sizeof(unsigned int));
+   attachments_with_format = calloc(count, 2 * sizeof(unsigned int));
    if (!attachments_with_format) {
       *out_count = 0;
       return NULL;