summaryrefslogtreecommitdiffstats
path: root/misc/bdfresize/check_factor_args.diff
blob: 5b9ad32e2cad0307d3a59ff8f912a51be21f6d5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;