From 9dc51140a5448d5e454bc2f8aac7ee14342216be Mon Sep 17 00:00:00 2001 From: Alexander Skoblikov Date: Tue, 24 May 2022 13:56:09 +0300 Subject: [PATCH] CB-1994 update rm errors --- .../model/rm/local/LocalResourceController.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java index 4ea6636e1e..7b0960dbda 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java @@ -36,6 +36,7 @@ import org.jkiss.utils.CommonUtils; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.time.OffsetDateTime; @@ -266,11 +267,15 @@ public class LocalResourceController implements RMController { throw new DBException("Error creating project path", e); } } - Path targetPath = projectPath.resolve(resourcePath).normalize(); - if (!targetPath.startsWith(projectPath)) { - throw new DBException("Invalid resource path"); + try { + Path targetPath = projectPath.resolve(resourcePath).normalize(); + if (!targetPath.startsWith(projectPath)) { + throw new DBException("Invalid resource path"); + } + return targetPath; + } catch (InvalidPathException e) { + throw new DBException("Resource path contains invalid characters"); } - return targetPath; } private RMProject makeProjectFromPath(Path path, String prefix, boolean checkExistence) {