gd_security.c 671 B

12345678910111213141516171819202122232425262728293031
  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. int overflow2(int a, int b)
  18. {
  19. if(a <= 0 || b <= 0) {
  20. php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
  21. return 1;
  22. }
  23. if(a > INT_MAX / b) {
  24. php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
  25. return 1;
  26. }
  27. return 0;
  28. }