On Tue, 5 Jan 2021 02:40:29 GMT, Yasumasa Suenaga <ysuen...@openjdk.org> wrote:
>> Marked as reviewed by iklam (Reviewer). > > @iklam Thanks for your review! > >> I looked at a cases in the JDK code where >> `Java_sun_security_pkcs11_wrapper_PKCS11_connect()` calls `FormatMessage()`. >> It eventually passes the `char*` to `jni_ThrowNew`, which eventually gets to >> `Exceptions::new_exception` with `to_utf8_safe==safe_to_utf8`. This means >> the message will be converted with `java_lang_String::create_from_str()`, >> which does NOT call `JNU_NewStringPlatform`. So I think in this case, the >> error message will also be garbled. >> >> java.base/windows/native/libnet/Inet4AddressImpl.c seems to have a similar >> problem in the `ping4` function. > > Agree. `ping4()` calls `NET_ThrowNew()` which passes `ThrowNew()` JNI > function without modifying arguments. > I looked at other cases in JDK code, following places has possible to garble: > > * `throwByName()` @ jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_util.c > * `Java_sun_security_pkcs11_Secmod_nssLoadLibrary()` @ j2secmod_md.c > * jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c > * `throwShmemException()` @ SharedMemoryTransport.c > >> But, I don't know how to write a simple test case for the above. > > Agree, we might need to fix garbled messages one by one when we find out > issues. > IMHO we need to establish rule that we have to use `JNU_NewStringPlatform()` > if we want to throw exception with message from platform (`FormatMessage()`, > `strerror()`) from JNI. Given that this seems to be a common problem in our code, and likely a very very old problem at that, why has it never been reported before? I'm not questioning the fix except to the extent that I'm questioning our understanding of the problem. ------------- PR: https://git.openjdk.java.net/jdk/pull/1928