summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2019-07-15 17:02:19 -0700
committerThiago Macieira <thiago.macieira@intel.com>2019-07-19 05:18:23 -0700
commit89e0c2854a9dc098380e5286b26de187d04f9826 (patch)
treeca16b8ef0f941e4ae9c282a2e08c6c8549a2de3d /src/corelib
parentc5ab86976b8836f3c4beff22a5138eb6f72c2c1e (diff)
Fix QStorageInfo inability to parse really long mountinfo lines
Docker creates really long lines due to the multiple levels of overlays in the overlayfs. Our limit of 1024 bytes was too short. [ChangeLog][QtCore][QStorageInfo] Fixed a bug that caused QStorageInfo to be unable to report all filesystems if the options to mounted filesystems were too long (over 900 characters, roughly), such as those found in Docker overlay mounts. Fixes: QTBUG-77059 Change-Id: I6aed4df6a12e43c3ac8efffd15b1ba4231e60b4a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index 11b5af069a..812e965927 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -468,8 +468,18 @@ inline bool QStorageIterator::next()
size_t len = strlen(buffer.data());
if (len == 0)
return false;
- if (ptr[len - 1] == '\n')
- ptr[len - 1] = '\0';
+ while (Q_UNLIKELY(ptr[len - 1] != '\n' && !feof(fp))) {
+ // buffer wasn't large enough. Enlarge and try again.
+ // (we're readidng from the kernel, so OOM is unlikely)
+ buffer.resize((buffer.size() + 4096) & ~4095);
+ ptr = buffer.data();
+ if (fgets(ptr + len, buffer.size() - len, fp) == nullptr)
+ return false;
+
+ len += strlen(ptr + len);
+ Q_ASSERT(len < size_t(buffer.size()));
+ }
+ ptr[len - 1] = '\0';
// parse the line
bool ok;