diff options
author | Andrey Loskutov | 2018-07-30 16:38:47 +0000 |
---|---|---|
committer | Andrey Loskutov | 2018-07-31 09:27:53 +0000 |
commit | b875986028b4c80f2afc67074756de6dff54d06c (patch) | |
tree | 9ef6ce2c33a3e4c3cf381b00a204b5d7b959eca1 | |
parent | 3e09f91d1f6476c4ef1718fb9cf272649463e27e (diff) | |
download | eclipse.platform.resources-b875986028b4c80f2afc67074756de6dff54d06c.tar.gz eclipse.platform.resources-b875986028b4c80f2afc67074756de6dff54d06c.tar.xz eclipse.platform.resources-b875986028b4c80f2afc67074756de6dff54d06c.zip |
Bug 537449 - added "trivial" checks for repeating back links to parentY20180815-2200Y20180808-2200Y20180801-2200S4_9_0_M2I20180820-0800I20180819-2000I20180819-0800I20180818-1500I20180818-0800I20180817-2000I20180816-2000I20180815-2000I20180815-1250I20180814-2000I20180814-0910I20180814-0900I20180813-2000I20180812-2000I20180811-1500I20180810-2000I20180810-0320I20180809-2000I20180808-2000I20180807-2000I20180807-1425I20180807-0350I20180806-2000I20180806-0300I20180805-2000I20180804-1500I20180803-2000I20180801-2000I20180801-0820I20180801-0800I20180801-0550I20180731-2000I20180731-1305I20180731-1250I20180731-1025
Allow "trivial" pattern match repeating back links and add checks if
those links are trivially recursive.
Change-Id: I5501f395e53604ec6f19c5c612950e36f9c31d00
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r-- | bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/UnifiedTree.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/UnifiedTree.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/UnifiedTree.java index 27999c85a..852adb9a2 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/UnifiedTree.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/UnifiedTree.java @@ -18,6 +18,7 @@ package org.eclipse.core.internal.localstore; import java.io.IOException; +import java.nio.file.Path; import java.util.*; import java.util.regex.Pattern; import org.eclipse.core.filesystem.*; @@ -399,6 +400,9 @@ public class UnifiedTree { //Pattern: A UNIX or Windows relative path that just points backward private static final String REGEX = Platform.getOS().equals(Platform.OS_WIN32) ? "\\.[.\\\\]*" : "\\.[./]*"; //$NON-NLS-1$ //$NON-NLS-2$ public static final Pattern TRIVIAL_SYMLINK_PATTERN = Pattern.compile(REGEX); + + private static final String REGEX_BACK_REPEATING = Platform.getOS().equals(Platform.OS_WIN32) ? "(\\.\\.\\\\)+.*" : "(\\.\\./)+.*"; //$NON-NLS-1$ //$NON-NLS-2$ + public static final Pattern REPEATING_BACKWARDS_PATTERN = Pattern.compile(REGEX_BACK_REPEATING); } /** @@ -469,21 +473,43 @@ public class UnifiedTree { if (linkTarget != null && PatternHolder.TRIVIAL_SYMLINK_PATTERN.matcher(linkTarget).matches()) { return true; } - if (disable_advanced_recursive_link_checks) { - // Skip advanced link checking, see bug 537449 - return false; - } //Need canonical paths to check all other possibilities try { java.io.File parentFile = parentStore.toLocalFile(EFS.NONE, null); //If this store cannot be represented as a local file, there is nothing we can do //In the future, we could try to resolve the link target //against the remote file system to do more checks. - if (parentFile == null) + if (parentFile == null) { + return false; + } + + Path parent = parentFile.toPath(); + Path realParentPath = parent.toRealPath(); + if (disable_advanced_recursive_link_checks) { + // Multiple ../ backwards links can go outside the project tree + if (linkTarget != null && PatternHolder.REPEATING_BACKWARDS_PATTERN.matcher(linkTarget).matches()) { + Path targetPath = parent.resolve(linkTarget).normalize(); + + // Recursive if literal target points to the literal parent of this tree + if (parent.normalize().startsWith(targetPath)) { + return true; + } + + // Recursive if resolved target points to the resolved parent of this tree + Path realTargetPath = targetPath.toRealPath(); + if (realParentPath.startsWith(realTargetPath)) { + return true; + } + + // If link is outside the project tree, consider as non recursive + // The link still can create recursion in the tree, but we can't detect it here. + } + // Skip advanced link checking, it may hide valid directories, see bug 537449 return false; + } //get canonical path for both child and parent java.io.File childFile = new java.io.File(parentFile, localInfo.getName()); - String parentPath = parentFile.toPath().toRealPath().toString() + java.io.File.separatorChar; + String parentPath = realParentPath.toString() + java.io.File.separatorChar; String childPath = childFile.toPath().toRealPath().toString() + java.io.File.separatorChar; //get or instantiate the prefix and root path histories. //Might be done earlier - for now, do it on demand. |