Re: [Boost-bugs] [Boost C++ Libraries] #5403: filesystem3::recursive_directory_iterator::increment(system::error_code& ec) unexpected behaviour

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5403: filesystem3::recursive_directory_iterator::increment(system::error_code& ec) unexpected behaviour
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-07-01 12:57:41


#5403: filesystem3::recursive_directory_iterator::increment(system::error_code&
ec) unexpected behaviour
--------------------------------------+-------------------------------------
  Reporter: ttan@… | Owner: bemandawes
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: filesystem
   Version: Boost Development Trunk | Severity: Showstopper
Resolution: | Keywords: recursive_directory_iterator increment
--------------------------------------+-------------------------------------

Comment (by Benjamin Herr <ben@…>):

 I just came across this bug trying to skip subdirectories that could not
 be accessed. In my case I received a segmentation fault on the ++ line:

 {{{
 system::error_code ec;
 iter.increment(ec);
 if (ec) {
   iter.no_push();
   ++iter;
 }
 }}}

 I believe the problem is in the line the previous comment identified.
 Unlike the `ec == 0` case, if the `directory_iterator` contructor fails
 and `*ec` is set to an error code, the invalid `directory_iterator` object
 is still added to the stack.

 In subsequent calls to `increment()`, it will eventually be incremented by
 the `while (!m_stack.empty() && ++m_stack.top() == directory_iterator())`
 loop, which is where the segfault happened.

 I believe a fix might be as simple as changing the aforementioned chunk to
 something like

 {{{
 directory_iterator it(m_stack.top()->path(), *ec);
 if (*ec)
   return;
 m_stack.push(it);
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5403#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC