SEGFAULT using boost::filesystem::recursive_directory_iterator

Bug #1188103 reported by Claudio Bley
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
boost1.48 (Ubuntu)
New
Undecided
Unassigned

Bug Description

When using the the increment(error_code) method of class recursive_directory_iterator
it fails to report the end iterator which leads to a SEGFAULT when trying to access the path of the (actually defunct) iterator.

Test code:

#include <boost/filesystem/operations.hpp>

using namespace boost::filesystem;
using namespace boost::system;

int main(int argc, char* argv[]) {
        if (argc != 2) return 1;

        error_code ec;
        for (recursive_directory_iterator start(argv[1], ec), end; start != end; start.increment(ec))
        {
            start->path();
        }
}

Compile with "g++ -g test.cpp -lboost_filesystem -lboost_system"

Run e.g. "gdb -ex run --args ./a.out /proc/$$"

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bcac11 in boost::filesystem3::directory_entry::m_get_status(boost::system::error_code*) const () from /usr/lib/libboost_filesystem.so.1.48.0

This bug was fixed upstream as part of SVN revision 76667 (http://lists.boost.org/boost-commit/2012/01/39358.php)

Here's a diff of the relevant part of that commit which fixes this problem:

--- operations.hpp.orig 2012-01-06 08:37:50.000000000 +0100
+++ operations.hpp 2013-06-06 11:08:58.223889240 +0200
@@ -782,6 +782,8 @@
       BOOST_ASSERT_MSG(m_imp.get(),
         "increment() on end recursive_directory_iterator");
       m_imp->increment(&ec);
+ if (m_imp->m_stack.empty())
+ m_imp.reset(); // done, so make end iterator
       return *this;
     }

Tags: patch
Claudio Bley (cbley)
tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.