Skip to content

Commit

Permalink
8335428: Enhanced Building of Processes
Browse files Browse the repository at this point in the history
Reviewed-by: mbalao, andrew
Backport-of: 978dfdf9aa95da4196055cc288c5993d4dc6ef85
  • Loading branch information
Yuri Nesterenko authored and gnu-andrew committed Jan 11, 2025
1 parent 7cee7d0 commit 8b25863
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/java.base/windows/classes/java/lang/ProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ private static String[] getTokensFromCommand(String command) {
private static final int VERIFICATION_LEGACY = 3;
// See Command shell overview for documentation of special characters.
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
private static final char ESCAPE_VERIFICATION[][] = {
private static final String ESCAPE_VERIFICATION[] = {
// We guarantee the only command file execution for implicit [cmd.exe] run.
// http://technet.microsoft.com/en-us/library/bb490954.aspx
{' ', '\t', '\"', '<', '>', '&', '|', '^'},
{' ', '\t', '\"', '<', '>'},
{' ', '\t', '\"', '<', '>'},
{' ', '\t'}
// All space characters require quoting are checked in needsEscaping().
"\t\"<>&|^",
"\t\"<>",
"\t\"<>",
"\t"
};

private static String createCommandLine(int verificationType,
Expand Down Expand Up @@ -332,9 +333,13 @@ private static boolean needsEscaping(int verificationType, String arg) {
}

if (!argIsQuoted) {
char testEscape[] = ESCAPE_VERIFICATION[verificationType];
for (int i = 0; i < testEscape.length; ++i) {
if (arg.indexOf(testEscape[i]) >= 0) {
for (int i = 0; i < arg.length(); i++) {
char ch = arg.charAt(i);
if (Character.isLetterOrDigit(ch))
continue; // skip over common characters
// All space chars require quotes and other mode specific characters
if (Character.isSpaceChar(ch) ||
ESCAPE_VERIFICATION[verificationType].indexOf(ch) >= 0) {
return true;
}
}
Expand Down

0 comments on commit 8b25863

Please sign in to comment.