Browse Source

Fortify against missing parameters

If user does not provide mandatory parameter, `shift 2` will fail but
will not shift anything, resulting in infinite loop.
Alois Mahdal 9 years ago
parent
commit
5f89128723
3 changed files with 5 additions and 5 deletions
  1. 3
    3
      src/libexec/saturnin-dmenu
  2. 1
    1
      src/libexec/saturnin-ln
  3. 1
    1
      src/libexec/saturnin-uris

+ 3
- 3
src/libexec/saturnin-dmenu View File

@@ -16,9 +16,9 @@ delim=" "
16 16
 field=2-
17 17
 
18 18
 while true; do case $1 in
19
-    -l|--lines)     lines=$2; shift 2 ;;
20
-    --split)        delim=$2; maybe_split=do_split; shift 2 ;;
21
-    --split-field)  field=$2; maybe_split=do_split; shift 2 ;;
19
+    -l|--lines)     lines=$2; shift 2 || usage ;;
20
+    --split)        delim=$2; maybe_split=do_split; shift 2 || usage ;;
21
+    --split-field)  field=$2; maybe_split=do_split; shift 2 || usage ;;
22 22
     --help|--usage) usage             ;;
23 23
     *)              break             ;;
24 24
 esac done

+ 1
- 1
src/libexec/saturnin-ln View File

@@ -31,7 +31,7 @@ load() {
31 31
 }
32 32
 
33 33
 while true; do case $1 in
34
-    -t|--target)        target=$2           shift 2 ;;
34
+    -t|--target)        target=$2           shift 2 || usage ;;
35 35
     --help)             usage                       ;;
36 36
     -*)                 usage                       ;;
37 37
     *)                  src=$1; name=$2;    break   ;;

+ 1
- 1
src/libexec/saturnin-uris View File

@@ -42,7 +42,7 @@ clipln() {
42 42
 
43 43
 src=args
44 44
 while true; do case "$1" in
45
-    -f) src=file; file=$2; shift 2 ;;
45
+    -f) src=file; file=$2; shift 2 || usage ;;
46 46
     -1) src=xpri;          shift   ;;
47 47
     -2) src=xsec;          shift   ;;
48 48
     -c) src=xclp;          shift   ;;