File: gd_security.c

package info (click to toggle)
libgd2 2.0.33-1.1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,240 kB
  • ctags: 1,275
  • sloc: ansic: 32,769; sh: 9,067; perl: 440; makefile: 122; tcl: 45
file content (33 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
   * gd_security.c
   *
   * Implements buffer overflow check routines.
   *
   * Written 2004, Phil Knirsch.
   * Based on netpbm fixes by Alan Cox.
   *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "gd.h"

int overflow2(int a, int b)
{
	if(a < 0 || b < 0) {
		fprintf(stderr, "gd warning: one parameter to a memory allocation multiplication is negative, failing operation gracefully\n");
		return 1;
	}
	if(b == 0)
		return 0;
	if(a > INT_MAX / b) {
		fprintf(stderr, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
		return 1;
	}
	return 0;
}