[Bug 776532] Re: nih_dir_walk_scan passes incorrect value to file filter

Dmitrijs Ledkovs launchpad at surgut.co.uk
Thu Mar 14 17:26:19 UTC 2013


This bug was fixed in the package libnih - 1.0.3-4ubuntu16

---------------
libnih (1.0.3-4ubuntu16) raring; urgency=low

  * debian/{libnih1.postinst,libnih-dbus1.postinst}: Force an upgrade to
    restart Upstart (to pick up new package version) if the running
    instance supports it.
  * Merge of important fixes from lp:~upstart-devel/libnih/nih
    (LP: #776532, LP: #777097, LP: #834813, LP: #1123588).
 -- James Hunt <james.hunt at ubuntu.com> Thu, 14 Mar 2013 09:14:22 +0000

** Also affects: libnih (Ubuntu)
   Importance: Undecided
       Status: New

** Changed in: libnih (Ubuntu)
       Status: New => Fix Released

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to libnih in Ubuntu.
https://bugs.launchpad.net/bugs/776532

Title:
  nih_dir_walk_scan passes incorrect value to file filter

Status in NIH Utility Library:
  Triaged
Status in “libnih” package in Ubuntu:
  Fix Released

Bug description:
  nih_watch_new() accepts a generic data pointer which is supposed to be
  passed to the create/modify/delete handlers *and* the file filter.
  However, there is a design issue in that the incorrect pointer is
  passed to the file filter as outlined in the psuedo-code below:

  1. When nih_watch_new() is called, it creates a new NihWatch object and sets "watch->data = data".
  2. nih_watch_add(watch, ...) is then called.
  3. nih_watch_add calls nih_dir_walk(path, filter=watch->filter, visitor=nih_watch_add_visitor, error=NULL, data=watch).
     (Note that "data=watch" here).
  4. nih_dir_walk() calls nih_dir_walk_scan(path, filter=watch->filter, data=watch).
  5. BUG: nih_dir_walk_scan() calls filter(data=watch).
  6. nih_dir_walk() then calls nih_dir_walk_visit(..., filter=watch->filter, visitor=nih_watch_add_filter, error=NULL, data=watch)
  7. nih_dir_walk_visit() calls visitor (data, ...) which resolves to:

     nih_watch_add_filter(NihWatch *watch, ...).

  
  Step 5 is incorrect. nih_dir_walk_scan() *should* call:

     filter(data=watch->data)

  However, it cannot since nih_dir_walk_scan knows nothing about
  NihWatches. The design issue comes down to the fact that the data
  pointer passed to nih_dir_walk() needs to be an NihWatch so it can be
  passed to nih_watch_add_visitor(), but it needs to be a true generic
  pointer, as set by the user via the data parameter to nih_watch_new().

  One possible solution would be to have *two* generic pointers passed
  to nih_dir_walk: one for the NihFileVisitor handler and the other for
  the NihFileFilter handler such that we would have something like:

  int
  nih_dir_walk (const char          *path,
                NihFileFilter        filter,
                NihFileVisitor       visitor,
                NihFileErrorHandler  error,             
                void                *visitor_data,      
                void                *filter_data)
  {
            :
      filter (filter_data);
            :
      visitor (visitor_data);
            :
  }

To manage notifications about this bug go to:
https://bugs.launchpad.net/libnih/+bug/776532/+subscriptions




More information about the foundations-bugs mailing list