Folder wizard: Fix infinite loop for bad paths #7041
authorChristian Kamm <mail@ckamm.de>
Mon, 18 Feb 2019 13:32:47 +0000 (14:32 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:42 +0000 (10:58 +0100)
src/gui/folderman.cpp

index b690a86d44e4dbf9447fa281716240270e523086..3991ca4b46ad804eb0b223cac269b0da932190ba 100644 (file)
@@ -1479,7 +1479,16 @@ static QString canonicalPath(const QString &path)
 {
     QFileInfo selFile(path);
     if (!selFile.exists()) {
-        return canonicalPath(selFile.dir().path()) + '/' + selFile.fileName();
+        const auto parentPath = selFile.dir().path();
+
+        // It's possible for the parentPath to match the path
+        // (possibly we've arrived at a non-existant drive root on Windows)
+        // and recursing would be fatal.
+        if (parentPath == path) {
+            return path;
+        }
+
+        return canonicalPath(parentPath) + '/' + selFile.fileName();
     }
     return selFile.canonicalFilePath();
 }