1 /*
2    * gd_security.c
3    *
4    * Implements buffer overflow check routines.
5    *
6    * Written 2004, Phil Knirsch.
7    * Based on netpbm fixes by Alan Cox.
8    *
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <limits.h>
18 #include "gd.h"
19 
overflow2(int a,int b)20 int overflow2(int a, int b)
21 {
22 	if(a < 0 || b < 0) {
23 		fprintf(stderr, "gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
24 		return 1;
25 	}
26 	if(b == 0)
27 		return 0;
28 	if(a > INT_MAX / b) {
29 		fprintf(stderr, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
30 		return 1;
31 	}
32 	return 0;
33 }
34