check_factor_args.diff 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. diff -Naur bdfresize-1.5/bdfresize.c bdfresize-1.5.patched/bdfresize.c
  2. --- bdfresize-1.5/bdfresize.c 2001-01-16 07:11:11.000000000 -0500
  3. +++ bdfresize-1.5.patched/bdfresize.c 2021-09-10 14:39:09.553534254 -0400
  4. @@ -48,6 +48,22 @@
  5. static int line;
  6. +static int factor_is_bad(const char *p) {
  7. + int slashes = 0;
  8. + while(*p) {
  9. + if(*p == '/') {
  10. + if(++slashes > 1)
  11. + return 1;
  12. + } else if(*p >= '0' && *p <= '9') {
  13. + /* NOP */
  14. + } else {
  15. + return 1;
  16. + }
  17. + p++;
  18. + }
  19. + return 0;
  20. +}
  21. +
  22. int
  23. main(int argc, char *argv[])
  24. {
  25. @@ -64,18 +80,21 @@
  26. if (blackness <= 0) err ++;
  27. break;
  28. case 'w':
  29. + err += factor_is_bad(optarg);
  30. numerator_x = atoi(optarg);
  31. denominator_x = strchr(optarg,'/')
  32. ? atoi(strchr(optarg,'/')+1) : 1;
  33. if (numerator_x <= 0 || denominator_x <= 0) err ++;
  34. break;
  35. case 'h':
  36. + err += factor_is_bad(optarg);
  37. numerator_y = atoi(optarg);
  38. denominator_y = strchr(optarg,'/')
  39. ? atoi(strchr(optarg,'/')+1) : 1;
  40. if (numerator_y <= 0 || denominator_y <= 0) err ++;
  41. break;
  42. case 'f':
  43. + err += factor_is_bad(optarg);
  44. numerator_x = numerator_y = atoi(optarg);
  45. denominator_x = denominator_y = strchr(optarg,'/')
  46. ? atoi(strchr(optarg,'/')+1) : 1;