gd_security.c 662 B

1234567891011121314151617181920212223242526272829303132
  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. #ifdef HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <limits.h>
  16. #include "gd.h"
  17. #include "gd_errors.h"
  18. int overflow2(int a, int b)
  19. {
  20. if(a <= 0 || b <= 0) {
  21. gd_error("One parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
  22. return 1;
  23. }
  24. if(a > INT_MAX / b) {
  25. gd_error("Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
  26. return 1;
  27. }
  28. return 0;
  29. }