Skip to content

Commit ada6bad

Browse files
committed
Add additional path segment to create a valid symlink
1 parent 335fe2d commit ada6bad

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryAdder.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424

2525
package org.jenkinsci.plugins.workflow.libs;
2626

27+
import hudson.AbortException;
28+
import hudson.Extension;
29+
import hudson.ExtensionList;
30+
import hudson.FilePath;
31+
import hudson.model.Queue;
32+
import hudson.model.Run;
33+
import hudson.model.TaskListener;
2734
import java.io.File;
2835
import java.io.IOException;
2936
import java.io.InputStream;
3037
import java.net.URL;
31-
import java.nio.file.Files;
32-
import java.nio.file.Path;
3338
import java.util.ArrayList;
3439
import java.util.Base64;
3540
import java.util.Collection;
@@ -38,10 +43,12 @@
3843
import java.util.LinkedHashMap;
3944
import java.util.List;
4045
import java.util.Map;
46+
import java.util.Set;
4147
import java.util.TreeMap;
4248
import java.util.logging.Level;
4349
import java.util.logging.Logger;
44-
50+
import edu.umd.cs.findbugs.annotations.CheckForNull;
51+
import edu.umd.cs.findbugs.annotations.NonNull;
4552
import org.apache.commons.io.IOUtils;
4653
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
4754
import org.jenkinsci.plugins.workflow.cps.GlobalVariable;
@@ -51,16 +58,6 @@
5158
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
5259
import org.jenkinsci.plugins.workflow.flow.FlowCopier;
5360

54-
import edu.umd.cs.findbugs.annotations.CheckForNull;
55-
import edu.umd.cs.findbugs.annotations.NonNull;
56-
import hudson.AbortException;
57-
import hudson.Extension;
58-
import hudson.ExtensionList;
59-
import hudson.FilePath;
60-
import hudson.model.Queue;
61-
import hudson.model.Run;
62-
import hudson.model.TaskListener;
63-
6461
/**
6562
* Given {@link LibraryResolver}, actually adds to the Groovy classpath.
6663
*/
@@ -260,15 +257,7 @@ static List<URL> retrieve(@NonNull LibraryRecord record, @NonNull LibraryRetriev
260257
for (LibraryRecord library : action.getLibraries()) {
261258
FilePath libResources = libs.child(library.getDirectoryName() + "/resources/");
262259
FilePath f = libResources.child(name);
263-
LOGGER.info("path: " + new File(f.getRemote()).getCanonicalFile().toPath());
264-
LOGGER.info("library path: " + new File(libResources.getRemote()).getCanonicalPath());
265-
File requestedFile = new File(f.getRemote()).getCanonicalFile();
266-
Path requestedFilePath = requestedFile.toPath();
267-
if (Files.isSymbolicLink(requestedFilePath)) {
268-
requestedFilePath = Files.readSymbolicLink(requestedFilePath).toFile().getCanonicalFile().toPath();
269-
}
270-
LOGGER.info("requested file path: " +requestedFilePath);
271-
if (!requestedFilePath.startsWith(new File(libResources.getRemote()).getCanonicalPath())) {
260+
if (!new File(f.getRemote()).getCanonicalFile().toPath().startsWith(new File(libResources.getRemote()).getCanonicalPath())) {
272261
throw new AbortException(name + " references a file that is not contained within the library: " + library.name);
273262
} else if (f.exists()) {
274263
resources.put(library.name, readResource(f, encoding));

src/test/java/org/jenkinsci/plugins/workflow/libs/ResourceStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public class ResourceStepTest {
195195
Path resourcesDir = Paths.get(sampleRepo.getRoot().getPath(), "resources");
196196
Files.createDirectories(resourcesDir);
197197
Path symlinkPath = Paths.get(resourcesDir.toString(), "master.key");
198-
Files.createSymbolicLink(symlinkPath, Paths.get("../../../../../../../secrets/master.key"));
198+
Files.createSymbolicLink(symlinkPath, Paths.get("../../../../../../../../secrets/master.key"));
199199

200200
sampleRepo.git("add", "src", "resources");
201201
sampleRepo.git("commit", "--message=init");

0 commit comments

Comments
 (0)