summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-05-03 19:44:11 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2018-07-13 12:47:53 +0000
commit41f737a12c46259a11361fd30c5f01414e990009 (patch)
tree80746589372492279c53b5f4ffa5cc7e388a1967 /src
parent33037150991a0dae0da769af8f46d1c15a27c728 (diff)
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 <oswald.buddenhagen@qt.io> Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com> Reviewed-by: Johannes Rosenqvist <xeroc81@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp7
1 files changed, 4 insertions, 3 deletions
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<QByteArray> 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);