From 41f737a12c46259a11361fd30c5f01414e990009 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 3 May 2018 19:44:11 +0200 Subject: Correct Unix QStorageInfo's QStorageIterator::next()'s loop logic The loop was accepting any line with at least three entries, but the code that then used this line needed four entries. At the same time, the loop's check had to be repeated, in rearranged form, after the loop, to handle some failing cases. Restructuring the loop, and demanding at least four entries, fixes all of this, although care must be taken about the virtual file-system lying about .atEnd(). [ChangeLog][QtCore][QStorageInfo] Fixed a bug on Android that could cause QStorageInfo to skip some filesystems (if the mount table is a virtual file and contains any short lines) or crash (if the mount table contains any 3-field lines). Change-Id: I1c2674372d0d0b7d16937de4345a910bc7d6e0ad Reviewed-by: Oswald Buddenhagen Reviewed-by: Ivan Komissarov Reviewed-by: Johannes Rosenqvist Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo_unix.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 15d78cb985..b7621b5d2f 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -342,13 +342,14 @@ inline bool QStorageIterator::isValid() const inline bool QStorageIterator::next() { QList data; + // If file is virtual, file.readLine() may succeed even when file.atEnd(). do { const QByteArray line = file.readLine(); + if (line.isEmpty() && file.atEnd()) + return false; data = line.split(' '); - } while (data.count() < 3 && !file.atEnd()); + } while (data.count() < 4); - if (file.atEnd() && data.count() <= 3) - return false; m_device = data.at(0); m_rootPath = data.at(1); m_fileSystemType = data.at(2); -- cgit v1.2.3