From cb4f853cb05bd57c0a00d9ca41b7e30bdd13bf9a Mon Sep 17 00:00:00 2001 From: Lu Zhen Date: Tue, 12 Jan 2021 20:37:05 +0800 Subject: [PATCH] Add some error handling for the inotify file system watcher In the readFromInotify() function, add a check whether the ioctl function is successful or not. In the case of failure, continuing to execute the following code would cause errors in the read function because there is no data in the buffer. Change-Id: Id53037e9e48c97c9eb75835048143875275b6370 Reviewed-by: Lars Knoll --- src/corelib/io/qfilesystemwatcher_inotify.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 94d9d06bcb..68e5ab7fa4 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -366,7 +366,9 @@ void QInotifyFileSystemWatcherEngine::readFromInotify() // qDebug("QInotifyFileSystemWatcherEngine::readFromInotify"); int buffSize = 0; - ioctl(inotifyFd, FIONREAD, (char *) &buffSize); + if (ioctl(inotifyFd, FIONREAD, (char *) &buffSize) == -1) + return; + QVarLengthArray buffer(buffSize); buffSize = read(inotifyFd, buffer.data(), buffSize); char *at = buffer.data();