Browse Source

don't rely on IntorspectionHelper normalizing file names in signjar. PR 50081.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1026982 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 14 years ago
parent
commit
38cd07c803
5 changed files with 52 additions and 5 deletions
  1. +5
    -0
      WHATSNEW
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Move.java
  3. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/SignJar.java
  4. +20
    -2
      src/main/org/apache/tools/ant/util/FileUtils.java
  5. +20
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java

+ 5
- 0
WHATSNEW View File

@@ -161,6 +161,11 @@ Fixed bugs:
make the exit codes work in environments where 4NT or MKS are installed
Bugzilla Report 41039.

* <signjar> would fail if used via its Java API and the File passed
into the setJar method was not "normalized" (i.e. contained ".."
segments).
Bugzilla Report 50081

Other changes:
--------------



+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -355,7 +355,7 @@ public class Move extends Copy {
+ " is a no-op.", Project.MSG_VERBOSE);
return true;
}
if (!(sourceFile.equals(destFile.getCanonicalFile()) || destFile.delete())) {
if (!(getFileUtils().areSame(sourceFile, destFile) || destFile.delete())) {
throw new BuildException("Unable to remove existing file " + destFile);
}
}


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/SignJar.java View File

@@ -378,7 +378,7 @@ public class SignJar extends AbstractJarSignerTask {
* @throws BuildException
*/
private void signOneJar(File jarSource, File jarTarget)
throws BuildException {
throws BuildException {


File targetFile = jarTarget;
@@ -401,12 +401,16 @@ public class SignJar extends AbstractJarSignerTask {
addValue(cmd, value);
}

try {
//DO NOT SET THE -signedjar OPTION if source==dest
//unless you like fielding hotspot crash reports
if (!jarSource.equals(targetFile)) {
if (!FILE_UTILS.areSame(jarSource, targetFile)) {
addValue(cmd, "-signedjar");
addValue(cmd, targetFile.getPath());
}
} catch (IOException ioex) {
throw new BuildException(ioex);
}

if (internalsf) {
addValue(cmd, "-internalsf");


+ 20
- 2
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1256,6 +1256,25 @@ public class FileUtils {
normalize(f2.getAbsolutePath()).getAbsolutePath());
}

/**
* Are the two File instances pointing to the same object on the
* file system?
* @since Ant 1.8.2
*/
public boolean areSame(File f1, File f2) throws IOException {
if (f1 == null && f2 == null) {
return true;
}
if (f1 == null || f2 == null) {
return false;
}
File f1Normalized = normalize(f1.getAbsolutePath());
File f2Normalized = normalize(f2.getAbsolutePath());
return f1Normalized.equals(f2Normalized)
|| f1Normalized.getCanonicalFile().equals(f2Normalized
.getCanonicalFile());
}

/**
* Renames a file, even if that involves crossing file system boundaries.
*
@@ -1285,8 +1304,7 @@ public class FileUtils {
System.err.println("Rename of " + from + " to " + to + " is a no-op.");
return;
}
if (to.exists() &&
!(from.equals(to.getCanonicalFile()) || tryHardToDelete(to))) {
if (to.exists() && !(areSame(from, to) || tryHardToDelete(to))) {
throw new IOException("Failed to delete " + to + " while trying to rename " + from);
}
File parent = to.getParentFile();


+ 20
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java View File

@@ -106,4 +106,24 @@ public class SignJarTest extends BuildFileTest {
}
}

/**
* @see https://issues.apache.org/bugzilla/show_bug.cgi?id=50081
*/
public void testSignUnnormalizedJar() throws Exception {
executeTarget("jar");
File testJar = new File(getProject().getProperty("test.jar"));
File testJarParent = testJar.getParentFile();
File f = new File(testJarParent,
"../" + testJarParent.getName() + "/"
+ testJar.getName());
assertFalse(testJar.equals(f));
assertEquals(testJar.getCanonicalPath(), f.getCanonicalPath());
SignJar s = new SignJar();
s.setProject(getProject());
s.setJar(f);
s.setAlias("testonly");
s.setStorepass("apacheant");
s.setKeystore("testkeystore");
s.execute();
}
}

Loading…
Cancel
Save