From 271a4c1af2244ce3a63b2d3179a85bebdede204d Mon Sep 17 00:00:00 2001 From: Antarpreet Singh Date: Mon, 29 Aug 2016 13:12:10 +0530 Subject: [PATCH] Fixed internal inconsistency on exception in last entry of recursive directory iterator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If there’s an exception during increment, the check to make end iterator is skipped. If this happens on the last element of recursive directory iterator, the iterator is left in a inconsistent state. --- include/boost/filesystem/operations.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/boost/filesystem/operations.hpp b/include/boost/filesystem/operations.hpp index fc697b03..21153c3f 100644 --- a/include/boost/filesystem/operations.hpp +++ b/include/boost/filesystem/operations.hpp @@ -1274,12 +1274,17 @@ namespace filesystem } void increment() - { + { BOOST_ASSERT_MSG(m_imp.get(), "increment of end recursive_directory_iterator"); - m_imp->increment(0); + system::error_code iec; + m_imp->increment(&iec); if (m_imp->m_stack.empty()) m_imp.reset(); // done, so make end iterator + if (iec) + BOOST_FILESYSTEM_THROW(filesystem_error( + "filesystem::recursive_directory_iterator directory error", + iec)); } bool equal(const recursive_directory_iterator& rhs) const