Bug 94323

Summary: pm-functions can incorrectly run hooks more than once
Product: pm-utils Reporter: /df <fieldhouse>
Component: GeneralAssignee: Richard Hughes <richard>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: medium CC: fieldhouse
Version: unspecified   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: patch taken from running pm-functions; also fixes comment typo
patch taken from running pm-functions; also fixes comment typo

Description /df 2016-02-28 01:54:18 UTC
Created attachment 122012 [details]
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.
Comment 1 /df 2016-02-28 01:59:57 UTC
Created attachment 122013 [details] [review]
patch taken from running pm-functions; also fixes comment typo

(attached wrong file)
Comment 2 Adam Jackson 2018-06-29 19:57:09 UTC
pm-utils hasn't been touched in eight years, none of this is likely to get addressed. Closing bugs and disabling the bz product.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.