Comment 12 for bug 1548486

Revision history for this message
In , Dirk F (fieldhouse) wrote :

Created attachment 122012
patch taken from running pm-functions; also fixes comment typo

The function run_hooks() in pm-functions proposes to-be-executed hooks that includes subdirectories in the hook directories but neither fully validates each such hook as a regular file nor handles a set of to-be-executed hooks in a subdirectory. This can cause a hook to be executed more than once.

At lines 241 on, there is a code path with no else clause:

  if [ -f "$syshooks/$base" ]; then
   hook="$syshooks/$base"
  elif [ -f "$phooks/$base" ]; then
   hook="$phooks/$base"
  fi

If the $base proposed by the for statement at line 229 doesn't match either of the -f tests (which will happen eg if a hook is configured in a subdirectory of the hook directory), the $hook from the previous iteration can be accidentally reused.

An easy fix is to insert the missing else clause before the fi line so that the script skips the subdirectory or other non-regular file and carries on with the next correctly specified hook, as in the attached patch.