slackbuilds/misc/bdfresize/check_factor_args.diff

49 lines
1.3 KiB
Diff

diff -Naur bdfresize-1.5/bdfresize.c bdfresize-1.5.patched/bdfresize.c
--- bdfresize-1.5/bdfresize.c 2001-01-16 07:11:11.000000000 -0500
+++ bdfresize-1.5.patched/bdfresize.c 2021-09-10 14:39:09.553534254 -0400
@@ -48,6 +48,22 @@
static int line;
+static int factor_is_bad(const char *p) {
+ int slashes = 0;
+ while(*p) {
+ if(*p == '/') {
+ if(++slashes > 1)
+ return 1;
+ } else if(*p >= '0' && *p <= '9') {
+ /* NOP */
+ } else {
+ return 1;
+ }
+ p++;
+ }
+ return 0;
+}
+
int
main(int argc, char *argv[])
{
@@ -64,18 +80,21 @@
if (blackness <= 0) err ++;
break;
case 'w':
+ err += factor_is_bad(optarg);
numerator_x = atoi(optarg);
denominator_x = strchr(optarg,'/')
? atoi(strchr(optarg,'/')+1) : 1;
if (numerator_x <= 0 || denominator_x <= 0) err ++;
break;
case 'h':
+ err += factor_is_bad(optarg);
numerator_y = atoi(optarg);
denominator_y = strchr(optarg,'/')
? atoi(strchr(optarg,'/')+1) : 1;
if (numerator_y <= 0 || denominator_y <= 0) err ++;
break;
case 'f':
+ err += factor_is_bad(optarg);
numerator_x = numerator_y = atoi(optarg);
denominator_x = denominator_y = strchr(optarg,'/')
? atoi(strchr(optarg,'/')+1) : 1;