On Fri, 4 Mar 2022 23:20:21 GMT, Roger Riggs <rri...@openjdk.org> wrote:

> Quoting related changes in https://bugs.openjdk.java.net/browse/JDK-8250568 
> modified the way that
> process builder recognized argument strings, causing some arguments to be 
> doubly quoted and malformed.
> 
> ProcessBuilder encodes command arguments in two ways, a looser legacy encoding
> and stricter encoding that prevents quotes from being misinterpreted.
> The system property jdk.lang.Process.allowAmbiguousCommands controls which is 
> in effect.
> 
> When the property is "true" or not set, arguments are inserted into the 
> Windows command line
> with minimal changes.  Arguments containing space or tab are quoted to 
> prevent them being split.
> Arguments that start and end with double-quote are left alone.
> Some executables interpret a backslash before the final quote as an escape; 
> if the argument 
> contains first and last quotes, backslashes are ignored.
> 
> When the allowAmbigousCommands property is `false`, care is taken to ensure 
> that
> the final quote of an argument is the closing quote for the argument and is 
> not
> interpreted as a literal quote by a preceding quote (or an odd number of 
> quotes).
> 
> The PR includes a test matrix of the cases where an argument with spaces and 
> a final backslash
> is passed with each combination of `allowAmbiguousCommands = true and false`,
> launched executable, java, .cmd, and .vbs and when the argument is surrounded 
> with double-quotes.
> 
> The priority for allowAmbiguousCommands = false is that no argument is split 
> or joined to another argument.
> In some cases, backslashes are doubled to prevent a double-quote from being 
> interpreted incorrectly.
> The trailing backslash in an argument occurs rarely exception when the 
> argument is a directory.
> In that case, the addition of trailing backslashes is benign when the string 
> is used as a filesystem path.
> 
> See also PR#7504, for background and a proposal.

This pull request has now been integrated.

Changeset: 897d6c0d
Author:    Roger Riggs <rri...@openjdk.org>
URL:       
https://git.openjdk.java.net/jdk/commit/897d6c0dc7cdfb3ad92f864f9ad4b50e642197e4
Stats:     343 lines in 2 files changed: 332 ins; 6 del; 5 mod

8282008: Incorrect handling of quoted arguments in ProcessBuilder

Reviewed-by: bchristi

-------------

PR: https://git.openjdk.java.net/jdk/pull/7709

Reply via email to