diff options
Diffstat (limited to 'config-lib/src/main/java/com')
4 files changed, 24 insertions, 7 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..3bcccb6d6b1 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. * @@ -13,7 +15,13 @@ public class FileNode extends LeafNode<FileReference> { public FileNode(String stringVal) { super(true); - this.value = new FileReference(ReferenceNode.stripQuotes(stringVal)); + Path path = Path.of(ReferenceNode.stripQuotes(stringVal)).normalize(); + if (path.isAbsolute()) + throw new IllegalArgumentException("path must be relative"); + if (path.startsWith("..")) + throw new IllegalArgumentException("'..' not allowed in path"); + + this.value = new FileReference(path.toString()); } public FileReference value() { diff --git a/config-lib/src/main/java/com/yahoo/config/Node.java b/config-lib/src/main/java/com/yahoo/config/Node.java index a07409b19e7..4f0c1c24192 100644 --- a/config-lib/src/main/java/com/yahoo/config/Node.java +++ b/config-lib/src/main/java/com/yahoo/config/Node.java @@ -14,7 +14,7 @@ public abstract class Node { * * @param configId the configId of the ConfigInstance that owns (or is) this node */ - public void postInitialize(String configId) { return; } + public void postInitialize(String configId) { } /** * This method is meant for internal use in the configuration system. diff --git a/config-lib/src/main/java/com/yahoo/config/NodeVector.java b/config-lib/src/main/java/com/yahoo/config/NodeVector.java index 3d07de944fd..af54c4d90ca 100644 --- a/config-lib/src/main/java/com/yahoo/config/NodeVector.java +++ b/config-lib/src/main/java/com/yahoo/config/NodeVector.java @@ -1,7 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; /** @@ -24,7 +28,6 @@ public abstract class NodeVector<NODE> implements java.util.List<NODE> { return size(); } - @SuppressWarnings("serial") public static class ReadOnlyException extends RuntimeException { } @@ -80,7 +83,7 @@ public abstract class NodeVector<NODE> implements java.util.List<NODE> { @Override public boolean equals(Object o) { - return o instanceof NodeVector && vector.equals(((NodeVector) o).vector); + return o instanceof NodeVector && vector.equals(((NodeVector<?>) o).vector); } @Override @@ -88,7 +91,6 @@ public abstract class NodeVector<NODE> implements java.util.List<NODE> { return vector.hashCode(); } - @SuppressWarnings("unchecked") public NODE get(int index) { return vector.get(index); } @@ -132,4 +134,5 @@ public abstract class NodeVector<NODE> implements java.util.List<NODE> { public <T> T[] toArray(T[] a) { return vector.toArray(a); } + } 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..2c43f89af3f 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,13 @@ public class PathNode extends LeafNode<Path> { public PathNode(FileReference fileReference) { super(true); - this.value = new File(fileReference.value()).toPath(); + Path value = Path.of(fileReference.value()).normalize(); + if (value.isAbsolute()) + throw new IllegalArgumentException("path must be relative"); + if (value.startsWith("..")) + throw new IllegalArgumentException("'..' not allowed in path"); + + this.value = value; this.fileReference = fileReference; } |