aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2022-03-31 11:20:06 +0200
committerJon Marius Venstad <venstad@gmail.com>2022-03-31 12:59:25 +0200
commit6478c2a16603f2f2163eb2116e58c363ab1cf37b (patch)
tree70420dae9deadd5282f1598bfd66b6f66490120a /config-lib/src/main/java/com/yahoo
parentf52ebfd454eb7b3c334e03b5c0ab47d4cb753e1f (diff)
Improve error message for invalid config
Diffstat (limited to 'config-lib/src/main/java/com/yahoo')
-rw-r--r--config-lib/src/main/java/com/yahoo/config/FileNode.java4
-rw-r--r--config-lib/src/main/java/com/yahoo/config/PathNode.java4
2 files changed, 7 insertions, 1 deletions
diff --git a/config-lib/src/main/java/com/yahoo/config/FileNode.java b/config-lib/src/main/java/com/yahoo/config/FileNode.java
index a7c1ebb1488..e6a4af6f439 100644
--- a/config-lib/src/main/java/com/yahoo/config/FileNode.java
+++ b/config-lib/src/main/java/com/yahoo/config/FileNode.java
@@ -1,6 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;
+import java.nio.file.Path;
+
/**
* Represents a 'file' in a {@link ConfigInstance}, usually a filename.
*
@@ -14,6 +16,8 @@ public class FileNode extends LeafNode<FileReference> {
public FileNode(String stringVal) {
super(true);
this.value = new FileReference(ReferenceNode.stripQuotes(stringVal));
+ if (Path.of(value.value()).normalize().startsWith(".."))
+ throw new IllegalArgumentException("path may not start with '..', but got: " + value.value());
}
public FileReference value() {
diff --git a/config-lib/src/main/java/com/yahoo/config/PathNode.java b/config-lib/src/main/java/com/yahoo/config/PathNode.java
index 1c4f724a7ed..03e6fb51086 100644
--- a/config-lib/src/main/java/com/yahoo/config/PathNode.java
+++ b/config-lib/src/main/java/com/yahoo/config/PathNode.java
@@ -23,7 +23,9 @@ public class PathNode extends LeafNode<Path> {
public PathNode(FileReference fileReference) {
super(true);
- this.value = new File(fileReference.value()).toPath();
+ this.value = Path.of(fileReference.value());
+ if (value.normalize().toString().startsWith(".."))
+ throw new IllegalArgumentException("path may not start with '..', but got :" + value);
this.fileReference = fileReference;
}