From 55f3cb95776f460c948b7df5187b87c2eff03633 Mon Sep 17 00:00:00 2001 From: kojima Date: Fri, 8 Nov 2002 18:00:56 +0000 Subject: [PATCH] argh! buffer overflow fix, try 3 :P --- wrlib/raster.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wrlib/raster.c b/wrlib/raster.c index 2048bdf9..0cfd2a9f 100644 --- a/wrlib/raster.c +++ b/wrlib/raster.c @@ -49,8 +49,18 @@ RCreateImage(unsigned width, unsigned height, int alpha) /* detect overflow (gr33tz to ruda :D) */ bla1 = width*height; + if (bla1 / height != width) { + RErrorCode = RERR_NOMEMORY; + return NULL; + } + bla2 = bla1*4; - if (bla1/height != width || bla2/4 != bla1 || bla2 > INT_MAX-32) { + if (bla2/4 != bla1) { + RErrorCode = RERR_NOMEMORY; + return NULL; + } + + if (bla2 > INT_MAX - 4) { RErrorCode = RERR_NOMEMORY; return NULL; } @@ -78,6 +88,7 @@ RCreateImage(unsigned width, unsigned height, int alpha) } return image; + }