From 10ee1b8d100e14f3478c1ce1c34431440bac4d18 Mon Sep 17 00:00:00 2001 From: Ben Bronk Date: Fri, 1 May 2020 15:40:43 +0200 Subject: [PATCH] Fix use of invalid find iterator in wxMemoryFSHandler Calling FindFirst() with an URL without wildcards returned the correct result, but didn't reset m_findIter, which kept its value from the previous search that could have been invalidated since then, e.g. if RemoveFile() has been called. Using this value could result in a crash during the next call to FindNext(). Fix this by ensuring that we always reset m_findIter to the valid (even if pointing to the end) value as the first thing we do in FindFirst(). Closes #18744. --- src/common/fs_mem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/fs_mem.cpp b/src/common/fs_mem.cpp index dd74323c36..93faa21487 100644 --- a/src/common/fs_mem.cpp +++ b/src/common/fs_mem.cpp @@ -123,6 +123,10 @@ wxFSFile * wxMemoryFSHandlerBase::OpenFile(wxFileSystem& WXUNUSED(fs), wxString wxMemoryFSHandlerBase::FindFirst(const wxString& url, int flags) { + // Make sure to reset the find iterator, so that calling FindNext() doesn't + // reuse its value from the last search that could well be invalid. + m_findIter = m_Hash.end(); + if ( (flags & wxDIR) && !(flags & wxFILE) ) { // we only store files, not directories, so we don't risk finding