argfiles parsing broken for argfiles > 4096 bytes
Robert Stupp
snazy at gmx.de
Thu Mar 5 19:00:50 UTC 2020
Hi,
I recently came across a bug in the java executable with an argfile
that's larger than 4096 bytes, if a 4096-byte-chunk ends in a comment
line.
One bug happens when the last character of a comment line is the 4096th
byte and the trailing newline is the first byte in the next chunk. In
that case, nextToken() in src/java.base/share/native/libjli/args.c
calls JLI_List_addSubstring (in the if-block at the end of nextToken())
with the contents of the current comment line. The next "valid" option
gets appended to that comment line and java errors out.
I've added some debugging output to the last if-block and pctx-
>state==FIND_NEXT and the the substring being added is the comment
line.
I've also tried and changed this line
http://hg.openjdk.java.net/jdk-updates/jdk11u/annotate/20e49753c388/src/java.base/share/native/libjli/args.c#l294
to 'if (anchor != nextc && pctx->state == IN_TOKEN)' and the argfile is
parsed correctly.
Steps to reproduce:1. save the attached my-argfile2. run 'java @my-
argfile my.className'3. java errors out with Error: Could not find or
load main class #
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-Dfoo=barCaused
by: java.lang.ClassNotFoundException: #
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-Dfoo=bar
With the above change (the attached patch in argfile-parse-bug.txt),
argfile parsing works as expected.Also updated the condition in the
loop looking for a comment's newline, as it looks inconsistent to the
condition in the loop for FIND_NEXT/SKIP_LEAD_WS and the condition of
the outer for-loop.
Robert
-------------- next part --------------
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# 23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# 2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-Dfoo=bar
-------------- next part --------------
diff -r 20e49753c388 src/java.base/share/native/libjli/args.c
--- a/src/java.base/share/native/libjli/args.c Wed Mar 04 15:26:22 2020 +0100
+++ b/src/java.base/share/native/libjli/args.c Thu Mar 05 19:57:55 2020 +0100
@@ -216,7 +216,7 @@
} else if (pctx->state == IN_COMMENT) {
while (ch != '\n' && ch != '\r') {
nextc++;
- if (nextc > eob) {
+ if (nextc >= eob) {
return NULL;
}
ch = *nextc;
@@ -291,7 +291,7 @@
}
assert(nextc == eob);
- if (anchor != nextc) {
+ if (anchor != nextc && pctx->state == IN_TOKEN) {
// not yet return until end of stream, we have part of a token.
JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
}
More information about the core-libs-dev
mailing list