Skip to content

Commit 3ba1d06

Browse files
Yuri NesterenkoRealCLanger
authored andcommitted
8335428: Enhanced Building of Processes
Reviewed-by: mbalao Backport-of: 978dfdf9aa95da4196055cc288c5993d4dc6ef85
1 parent 6150578 commit 3ba1d06

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/java.base/windows/classes/java/lang/ProcessImpl.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ private static String[] getTokensFromCommand(String command) {
216216
private static final int VERIFICATION_LEGACY = 3;
217217
// See Command shell overview for documentation of special characters.
218218
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
219-
private static final char ESCAPE_VERIFICATION[][] = {
219+
private static final String ESCAPE_VERIFICATION[] = {
220220
// We guarantee the only command file execution for implicit [cmd.exe] run.
221221
// http://technet.microsoft.com/en-us/library/bb490954.aspx
222-
{' ', '\t', '\"', '<', '>', '&', '|', '^'},
223-
{' ', '\t', '\"', '<', '>'},
224-
{' ', '\t', '\"', '<', '>'},
225-
{' ', '\t'}
222+
// All space characters require quoting are checked in needsEscaping().
223+
"\t\"<>&|^",
224+
"\t\"<>",
225+
"\t\"<>",
226+
"\t"
226227
};
227228

228229
private static String createCommandLine(int verificationType,
@@ -337,9 +338,13 @@ private static boolean needsEscaping(int verificationType, String arg) {
337338
}
338339

339340
if (!argIsQuoted) {
340-
char testEscape[] = ESCAPE_VERIFICATION[verificationType];
341-
for (int i = 0; i < testEscape.length; ++i) {
342-
if (arg.indexOf(testEscape[i]) >= 0) {
341+
for (int i = 0; i < arg.length(); i++) {
342+
char ch = arg.charAt(i);
343+
if (Character.isLetterOrDigit(ch))
344+
continue; // skip over common characters
345+
// All space chars require quotes and other mode specific characters
346+
if (Character.isSpaceChar(ch) ||
347+
ESCAPE_VERIFICATION[verificationType].indexOf(ch) >= 0) {
343348
return true;
344349
}
345350
}

0 commit comments

Comments
 (0)