Browse Source

Fortify hook routine

Add checks for syntax errors and missing SATURNIN_SUBCOMMAND.  In both
cases, ignore the hook.
Alois Mahdal 9 years ago
parent
commit
066c22b204
1 changed files with 16 additions and 3 deletions
  1. 16
    3
      src/bin/saturnin.skel

+ 16
- 3
src/bin/saturnin.skel View File

@@ -65,9 +65,22 @@ version_info() {
65 65
 }
66 66
 
67 67
 run_hook() {
68
-    inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$1 \
69
-      | debug_pipe hook_$1 \
70
-      | bash
68
+    #
69
+    # Run custom hook
70
+    #
71
+    local hname="$1"
72
+    local hook_code
73
+    test -n "$SATURNIN_SUBCOMMAND" || {
74
+        warn "unknown subcommand, ignoring hook: $hname"
75
+        return 0
76
+    }
77
+    hook_code="$(inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$hname)"
78
+    debug -v SATURNIN_SUBCOMMAND hook_code hname
79
+    bash -n <<<"$hook_code" || {
80
+        warn "syntax errors, ignoring hook: $hname"
81
+        return 0
82
+    }
83
+    eval "$hook_code"
71 84
 }
72 85
 
73 86
 subcommand() {