/src/libgd/src/gd_security.c
Line | Count | Source |
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 | | #include "gd_errors.h" |
20 | | |
21 | | int overflow2(int a, int b) |
22 | 7.45k | { |
23 | 7.45k | if(a <= 0 || b <= 0) { |
24 | 65 | gd_error_ex(GD_WARNING, "one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n"); |
25 | 65 | return 1; |
26 | 65 | } |
27 | 7.38k | if(a > 100000 / b) { |
28 | 184 | gd_error_ex(GD_WARNING, "product of memory allocation multiplication would exceed 100000, failing operation gracefully\n"); |
29 | 184 | return 1; |
30 | 184 | } |
31 | 7.20k | return 0; |
32 | 7.38k | } |