Back to index

php5  5.3.10
gd_security.c
Go to the documentation of this file.
00001 /*
00002    * gd_security.c
00003    *
00004    * Implements buffer overflow check routines.
00005    *
00006    * Written 2004, Phil Knirsch.
00007    * Based on netpbm fixes by Alan Cox.
00008    *
00009  */
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif
00014 
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <limits.h>
00018 #include "gd.h"
00019 
00020 int overflow2(int a, int b)
00021 {
00022        if(a <= 0 || b <= 0) {
00023               php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
00024               return 1;
00025        }
00026        if(a > INT_MAX / b) {
00027               php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
00028               return 1;
00029        }
00030        return 0;
00031 }