Back to index

tetex-bin  3.0
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               fprintf(stderr, "gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
00024               return 1;
00025        }
00026        if(b == 0)
00027               return 0;
00028        if(a > INT_MAX / b) {
00029               fprintf(stderr, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
00030               return 1;
00031        }
00032        return 0;
00033 }