From 1cb20ea690d5d43106a303ac9d74f47e2d61fc5c Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Sat, 22 Mar 2008 23:05:37 +0000 Subject: [PATCH] fix for 43799: ManifestClassPath cannot traverse system root git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@640118 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ .../org/apache/tools/ant/taskdefs/ManifestClassPath.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 5836e81c9..e8843a292 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -52,6 +52,9 @@ Fixed bugs: * task couldn't differentiate between "no resources specified" and "no resources matched." Bugzilla report 43799. + + * ManifestClassPath throws when a relative path would traverse the file system root. Bugzilla + report 44499. Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java b/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java index f980620b2..665dfdef2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java +++ b/src/main/org/apache/tools/ant/taskdefs/ManifestClassPath.java @@ -75,7 +75,10 @@ public class ManifestClassPath extends Task { File currDir = dir; String[] dirs = new String[maxParentLevels + 1]; for (int i = 0; i < maxParentLevels + 1; ++i) { - dirs[i] = currDir.getAbsolutePath() + File.separatorChar; + dirs[i] = currDir.getAbsolutePath(); + if (!dirs[i].equals("" + File.separatorChar)) { + dirs[i] = dirs[i] + File.separatorChar; + } currDir = currDir.getParentFile(); if (currDir == null) { maxParentLevels = i + 1; @@ -95,7 +98,7 @@ public class ManifestClassPath extends Task { // Find the longest prefix shared by the current file // and the reference directory. String relPath = null; - for (int j = 0; j <= maxParentLevels; ++j) { + for (int j = 0; j <= maxParentLevels && j < dirs.length; ++j) { String dir = dirs[j]; if (!fullPath.startsWith(dir)) { continue;