RFR: 8299340: CreateProcessW lpCommandLine must be mutable

Naoto Sato naoto at openjdk.org
Fri May 12 18:00:50 UTC 2023


On Tue, 9 May 2023 21:46:51 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

> Launching of processes on Windows using `ProcessCreateW` with a Unicode character set requires the buffer to be writable. An access violation might occur if `ProcessCreateW` writes to the command line string. The current implementation fetches the command line string using JNI GetStringChars returning a buffer that should not be modified. The code is unchanged since 2015.  There have not been any reported faults in that time.
> 
> This change copies the command line to a separately allocation mutable buffer to satisfy the Windows requirement.

src/java.base/windows/native/libjava/ProcessImpl_md.c line 385:

> 383:                         // Copy command line to mutable char buffer; CreateProcessW may modify it
> 384:                         jsize cmdLen = (*env)->GetStringLength(env, cmd);
> 385:                         WCHAR *pcmdCopy = (WCHAR*)malloc(cmdLen * sizeof(WCHAR));

Should this include null terminator, as it is interpreted as `LPWSTR` which is null-terminated?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13894#discussion_r1192655747


More information about the core-libs-dev mailing list