mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8231863: Crash if classpath is read from @argument file and the main gets option argument
Reviewed-by: alanb, mchung
This commit is contained in:
parent
a4c01b3c46
commit
f390c87d8d
3 changed files with 41 additions and 7 deletions
|
@ -337,7 +337,9 @@ static JLI_List readArgFile(FILE *file) {
|
||||||
// remaining partial token
|
// remaining partial token
|
||||||
if (ctx.state == IN_TOKEN || ctx.state == IN_QUOTE) {
|
if (ctx.state == IN_TOKEN || ctx.state == IN_QUOTE) {
|
||||||
if (ctx.parts->size != 0) {
|
if (ctx.parts->size != 0) {
|
||||||
JLI_List_add(rv, JLI_List_combine(ctx.parts));
|
token = JLI_List_combine(ctx.parts);
|
||||||
|
checkArg(token);
|
||||||
|
JLI_List_add(rv, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JLI_List_free(ctx.parts);
|
JLI_List_free(ctx.parts);
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8027634
|
* @bug 8027634 8231863
|
||||||
* @summary Argument parsing from file
|
* @summary Argument parsing from file
|
||||||
* @modules jdk.compiler
|
* @modules jdk.compiler
|
||||||
* jdk.zipfs
|
* jdk.zipfs
|
||||||
|
@ -61,13 +61,17 @@ public class ArgsFileTest extends TestHelper {
|
||||||
env.put(JLDEBUG_KEY, "true");
|
env.put(JLDEBUG_KEY, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
private File createArgFile(String fname, List<String> lines) throws IOException {
|
private File createArgFile(String fname, List<String> lines, boolean endWithNewline) throws IOException {
|
||||||
File argFile = new File(fname);
|
File argFile = new File(fname);
|
||||||
argFile.delete();
|
argFile.delete();
|
||||||
createAFile(argFile, lines);
|
createAFile(argFile, lines, endWithNewline);
|
||||||
return argFile;
|
return argFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File createArgFile(String fname, List<String> lines) throws IOException {
|
||||||
|
return createArgFile(fname, lines, true);
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyOptions(List<String> args, TestResult tr) {
|
private void verifyOptions(List<String> args, TestResult tr) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -266,6 +270,23 @@ public class ArgsFileTest extends TestHelper {
|
||||||
userArgs.delete();
|
userArgs.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void userApplicationWithoutEmptyLastLine() throws IOException {
|
||||||
|
File cpOpt = createArgFile("cpOpt", Arrays.asList("-classpath ."), false);
|
||||||
|
File vmArgs = createArgFile("vmArgs", Arrays.asList("-Xint"), false);
|
||||||
|
|
||||||
|
TestResult tr = doExec(env, javaCmd, "-cp", "test.jar", "@cpOpt", "Foo", "-test");
|
||||||
|
verifyOptions(Arrays.asList("-cp", "test.jar", "-classpath", ".", "Foo", "-test"), tr);
|
||||||
|
verifyUserArgs(Arrays.asList("-test"), tr, 6);
|
||||||
|
|
||||||
|
tr = doExec(env, javaCmd, "-cp", "test.jar", "@vmArgs", "Foo", "-test");
|
||||||
|
verifyOptions(Arrays.asList("-cp", "test.jar", "-Xint", "Foo", "-test"), tr);
|
||||||
|
verifyUserArgs(Arrays.asList("-test"), tr, 5);
|
||||||
|
|
||||||
|
cpOpt.delete();
|
||||||
|
vmArgs.delete();
|
||||||
|
}
|
||||||
|
|
||||||
// test with missing file
|
// test with missing file
|
||||||
@Test
|
@Test
|
||||||
public void missingFileNegativeTest() throws IOException {
|
public void missingFileNegativeTest() throws IOException {
|
||||||
|
|
|
@ -349,12 +349,23 @@ public class TestHelper {
|
||||||
* occurs then back off for a moment and try again. When a number of
|
* occurs then back off for a moment and try again. When a number of
|
||||||
* attempts fail, give up and throw an exception.
|
* attempts fail, give up and throw an exception.
|
||||||
*/
|
*/
|
||||||
void createAFile(File aFile, List<String> contents) throws IOException {
|
void createAFile(File aFile, List<String> lines) throws IOException {
|
||||||
|
createAFile(aFile, lines, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createAFile(File aFile, List<String> lines, boolean endWithNewline) throws IOException {
|
||||||
IOException cause = null;
|
IOException cause = null;
|
||||||
for (int attempts = 0; attempts < 10; attempts++) {
|
for (int attempts = 0; attempts < 10; attempts++) {
|
||||||
try {
|
try {
|
||||||
Files.write(aFile.getAbsoluteFile().toPath(), contents,
|
if (endWithNewline) {
|
||||||
Charset.defaultCharset(), CREATE, TRUNCATE_EXISTING, WRITE);
|
Files.write(aFile.getAbsoluteFile().toPath(),
|
||||||
|
lines, Charset.defaultCharset(),
|
||||||
|
CREATE, TRUNCATE_EXISTING, WRITE);
|
||||||
|
} else {
|
||||||
|
Files.write(aFile.getAbsoluteFile().toPath(),
|
||||||
|
String.join(System.lineSeparator(), lines).getBytes(Charset.defaultCharset()),
|
||||||
|
CREATE, TRUNCATE_EXISTING, WRITE);
|
||||||
|
}
|
||||||
if (cause != null) {
|
if (cause != null) {
|
||||||
/*
|
/*
|
||||||
* report attempts and errors that were encountered
|
* report attempts and errors that were encountered
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue