On Fri, 12 May 2023 17:56:08 GMT, Naoto Sato <na...@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? It seems like it should now. Java strings are not null terminated and any null termination would have accidental. But it has worked for a long time (2013) without explicit Unicode null termination. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/13894#discussion_r1192685105