Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit dc17821

Browse files
committedMar 6, 2020
8240629: argfiles parsing broken for argfiles with comment cross 4096 bytes chunk
Reviewed-by: alanb, mchung
1 parent aa2be11 commit dc17821

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed
 

‎src/java.base/share/native/libjli/args.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,12 @@ static char* nextToken(__ctx_args *pctx) {
218218
} else if (pctx->state == IN_COMMENT) {
219219
while (ch != '\n' && ch != '\r') {
220220
nextc++;
221-
if (nextc > eob) {
221+
if (nextc >= eob) {
222222
return NULL;
223223
}
224224
ch = *nextc;
225225
}
226+
anchor = nextc + 1;
226227
pctx->state = FIND_NEXT;
227228
continue;
228229
}
@@ -258,6 +259,7 @@ static char* nextToken(__ctx_args *pctx) {
258259
continue;
259260
}
260261
pctx->state = IN_COMMENT;
262+
anchor = nextc + 1;
261263
break;
262264
case '\\':
263265
if (pctx->state != IN_QUOTE) {
@@ -293,9 +295,12 @@ static char* nextToken(__ctx_args *pctx) {
293295
}
294296

295297
assert(nextc == eob);
296-
if (anchor != nextc) {
297-
// not yet return until end of stream, we have part of a token.
298-
JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
298+
// Only need partial token, not comment or whitespaces
299+
if (pctx->state == IN_TOKEN || pctx->state == IN_QUOTE) {
300+
if (anchor < nextc) {
301+
// not yet return until end of stream, we have part of a token.
302+
JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
303+
}
299304
}
300305
return NULL;
301306
}

‎test/jdk/tools/launcher/ArgFileSyntax.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @test
26-
* @bug 8027634 8210810
26+
* @bug 8027634 8210810 8240629
2727
* @summary Verify syntax of argument file
2828
* @build TestHelper
2929
* @run main ArgFileSyntax
@@ -36,7 +36,6 @@
3636
import java.util.HashMap;
3737
import java.util.List;
3838
import java.util.Map;
39-
import java.util.regex.Matcher;
4039
import java.util.regex.Pattern;
4140

4241
public class ArgFileSyntax extends TestHelper {
@@ -213,10 +212,28 @@ public List<List<List<String>>> loadCases() {
213212
scratch.add(bag + "'" + filling + "\\\\aaa\\\\'");
214213
scratch.add(ver);
215214
rv.add(List.of(scratch, List.of(bag + filling + "\\aaa\\", ver)));
216-
217215
return rv;
218216
}
219217

218+
// 8240629: end or start comment at boundary
219+
@Test
220+
public void test8240629() throws IOException {
221+
char[] data = new char[ARG_FILE_PARSER_BUF_SIZE];
222+
data[0] = '#';
223+
Arrays.fill(data, 1, data.length, '0');
224+
225+
int need = ARG_FILE_PARSER_BUF_SIZE - System.lineSeparator().length();
226+
// Comment end before, at, after boundary
227+
for (int count = need - 1; count <= need + 1 ; count++) {
228+
String commentAtBoundary = String.valueOf(data, 0, count);
229+
List<String> content = new ArrayList<>();
230+
content.add(commentAtBoundary);
231+
content.add("# start a new comment at boundary");
232+
content.add("-Dfoo=bar");
233+
verifyParsing(content, List.of("-Dfoo=bar"));
234+
}
235+
}
236+
220237
// ensure the arguments in the file are read in correctly
221238
private void verifyParsing(List<String> lines, List<String> args) throws IOException {
222239
File argFile = createArgFile(lines);

0 commit comments

Comments
 (0)
This repository has been archived.