Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Please login to access the resource
home:dirkmueller:branches:openSUSE:Factory:Rings:1-MinimalX
qt6-base
0001-QDirIterator-don-t-crash-with-next-after-h...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0001-QDirIterator-don-t-crash-with-next-after-hasNext-ret.patch of Package qt6-base
From 55a8050d1e762befeeb5ba557f458b0092cbb44b Mon Sep 17 00:00:00 2001 From: Ahmad Samir <a.samirh78@gmail.com> Date: Wed, 16 Oct 2024 19:26:25 +0300 Subject: [PATCH] QDirIterator: don't crash with next() after hasNext() returned false The typical use-case is calling hasNext() first before using next, but the API docs say that calling next() even when hasNext() is false, should just return an empty string. [ChangeLog][QtCore][QDirIterator] Fixed a crash that happened if you called next() after hasNext() had already returned false. Ideally you should never call next() without first calling hasNext() as that could lead to unexpected results (for example, infinite loops). Fixes: QTBUG-130142 Change-Id: If0a8b1fe7dbd13b45793409a7a241e53c7257f24 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c7691842f743f568a073582c8f0cacd6ee188f98) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> --- src/corelib/io/qdiriterator.cpp | 5 +++++ .../auto/corelib/io/qdiriterator/tst_qdiriterator.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp index faea8088cb..7d7fe15684 100644 --- a/src/corelib/io/qdiriterator.cpp +++ b/src/corelib/io/qdiriterator.cpp @@ -103,6 +103,11 @@ public: void advance() { + // Match the behavior of advance() from before porting to QDirListing, + // that is, even if hasNext() returns false, calling next() returns an + // empty string without crashing. QTBUG-130142 + if (it == lister.end()) + return; currentFileInfo = nextFileInfo; if (++it != lister.end()) { nextFileInfo = it->fileInfo(); diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index a0a8917c27..b739f0eb11 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -86,6 +86,8 @@ private slots: void hiddenDirs_hiddenFiles(); #endif + void hasNextFalseNoCrash(); + private: QSharedPointer<QTemporaryDir> m_dataDir; }; @@ -642,6 +644,15 @@ void tst_QDirIterator::hiddenDirs_hiddenFiles() } #endif // Q_OS_WIN +void tst_QDirIterator::hasNextFalseNoCrash() +{ + QDirIterator iter(u"empty"_s, QDir::NoDotAndDotDot); + // QTBUG-130142 + // No crash if you call next() after hasNext() returned false + QVERIFY(!iter.hasNext()); + QVERIFY(iter.next().isEmpty()); +} + QTEST_MAIN(tst_QDirIterator) #include "tst_qdiriterator.moc" -- 2.47.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor