8248112: array index out of bound in FileMapInfo::check_paths
Check runtime classpath lengths after calling create_path_array(). Reviewed-by: iklam, minqi
This commit is contained in:
parent
e87c864847
commit
ddcb17e1e0
@ -714,6 +714,11 @@ bool FileMapInfo::validate_boot_class_paths() {
|
||||
num = rp_len;
|
||||
}
|
||||
mismatch = check_paths(1, num, rp_array);
|
||||
} else {
|
||||
// create_path_array() ignores non-existing paths. Although the dump time and runtime boot classpath lengths
|
||||
// are the same initially, after the call to create_path_array(), the runtime boot classpath length could become
|
||||
// shorter. We consider boot classpath mismatch in this case.
|
||||
mismatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -740,6 +745,12 @@ bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) {
|
||||
// None of the jar file specified in the runtime -cp exists.
|
||||
return classpath_failure("None of the jar file specified in the runtime -cp exists: -Djava.class.path=", appcp);
|
||||
}
|
||||
if (rp_array->length() < shared_app_paths_len) {
|
||||
// create_path_array() ignores non-existing paths. Although the dump time and runtime app classpath lengths
|
||||
// are the same initially, after the call to create_path_array(), the runtime app classpath length could become
|
||||
// shorter. We consider app classpath mismatch in this case.
|
||||
return classpath_failure("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
|
||||
}
|
||||
|
||||
// Handling of non-existent entries in the classpath: we eliminate all the non-existent
|
||||
// entries from both the dump time classpath (ClassLoader::update_class_path_entry_list)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,6 +28,7 @@
|
||||
* @requires vm.cds
|
||||
* @library /test/lib
|
||||
* @compile test-classes/Hello.java
|
||||
* @compile test-classes/C2.java
|
||||
* @run driver BootClassPathMismatch
|
||||
*/
|
||||
|
||||
@ -61,6 +62,7 @@ public class BootClassPathMismatch {
|
||||
test.testBootClassPathMatchWithAppend();
|
||||
}
|
||||
test.testBootClassPathMatch();
|
||||
test.testBootClassPathMismatchTwoJars();
|
||||
}
|
||||
|
||||
/* Archive contains boot classes only, with Hello class on -Xbootclasspath/a path.
|
||||
@ -215,6 +217,25 @@ public class BootClassPathMismatch {
|
||||
.assertAbnormalExit(mismatchMessage);
|
||||
}
|
||||
|
||||
/* Archive contains app classes, with 2 jars in bootclasspath at dump time.
|
||||
*
|
||||
* Error should be detected if:
|
||||
* dump time: -Xbootclasspath/a:hello.jar:jar2.jar
|
||||
* run-time : -Xbootclasspath/a:hello.jar:jar2.jarx
|
||||
* Note: the second jar (jar2.jarx) specified for run-time doesn't exist.
|
||||
*/
|
||||
public void testBootClassPathMismatchTwoJars() throws Exception {
|
||||
String appJar = JarBuilder.getOrCreateHelloJar();
|
||||
String jar2 = ClassFileInstaller.writeJar("jar2.jar", "pkg/C2");
|
||||
String jars = appJar + File.pathSeparator + jar2;
|
||||
String appClasses[] = {"Hello", "pkg/C2"};
|
||||
TestCommon.dump(
|
||||
appJar, appClasses, "-Xbootclasspath/a:" + jars);
|
||||
TestCommon.run(
|
||||
"-cp", appJar, "-Xbootclasspath/a:" + jars + "x", "Hello")
|
||||
.assertAbnormalExit(mismatchMessage);
|
||||
}
|
||||
|
||||
private static void copyHelloToNewDir() throws Exception {
|
||||
String classDir = System.getProperty("test.classes");
|
||||
String dstDir = classDir + File.separator + "newdir";
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,9 +28,11 @@
|
||||
* @requires vm.cds
|
||||
* @library /test/lib
|
||||
* @compile test-classes/Hello.java
|
||||
* @compile test-classes/C2.java
|
||||
* @run driver WrongClasspath
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
public class WrongClasspath {
|
||||
@ -48,5 +50,16 @@ public class WrongClasspath {
|
||||
"Hello")
|
||||
.assertAbnormalExit("Unable to use shared archive",
|
||||
"shared class paths mismatch");
|
||||
|
||||
// Dump CDS archive with 2 jars: -cp hello.jar:jar2.jar
|
||||
// Run with 2 jars but the second jar doesn't exist: -cp hello.jarjar2.jarx
|
||||
// Shared class paths mismatch should be detected.
|
||||
String jar2 = ClassFileInstaller.writeJar("jar2.jar", "pkg/C2");
|
||||
String jars = appJar + File.pathSeparator + jar2;
|
||||
TestCommon.testDump(jars, TestCommon.list("Hello", "pkg/C2"));
|
||||
TestCommon.run(
|
||||
"-cp", jars + "x", "Hello")
|
||||
.assertAbnormalExit("Unable to use shared archive",
|
||||
"shared class paths mismatch");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user