prevent injecting invalid modified time through CfApi calls
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 7 Dec 2021 13:44:08 +0000 (14:44 +0100)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Wed, 8 Dec 2021 07:22:24 +0000 (07:22 +0000)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/vfs/cfapi/cfapiwrapper.cpp

index 09fb3764ae13d0befa595ec0e6b0f2e5bea7d4ac..16b9d8f7e392ef53051df6db551b04eecf08dfd7 100644 (file)
@@ -643,6 +643,10 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::se
 
 OCC::Result<void, QString> OCC::CfApiWrapper::createPlaceholderInfo(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId)
 {
+    if (modtime <= 0) {
+        return {QString{"Could not update metadata due to invalid modified time for %1: %2"}.arg(path).arg(modtime)};
+    }
+
     const auto fileInfo = QFileInfo(path);
     const auto localBasePath = QDir::toNativeSeparators(fileInfo.path()).toStdWString();
     const auto relativePath = fileInfo.fileName().toStdWString();
@@ -691,6 +695,10 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::up
 {
     Q_ASSERT(handle);
 
+    if (modtime <= 0) {
+        return {QString{"Could not update metadata due to invalid modified time for %1: %2"}.arg(pathForHandle(handle)).arg(modtime)};
+    }
+
     const auto info = replacesPath.isEmpty() ? findPlaceholderInfo(handle)
                                              : findPlaceholderInfo(handleForPath(replacesPath));
     if (!info) {