[jdk8u-dev] RFR: 8339414: Fix JDK-8202369 incorrect backport for 8u [v2]
Andrew John Hughes
andrew at openjdk.org
Fri Jun 6 16:50:01 UTC 2025
On Thu, 5 Jun 2025 23:27:41 GMT, Thomas Fitzsimmons <duke at openjdk.org> wrote:
>> There is a large `#ifdef` in JDK 8's `Inet4AddressImpl.c`:
>>
>>
>> #if defined(__GLIBC__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 601104))
>> #define HAS_GLIBC_GETHOSTBY_R 1
>> #endif
>>
>> #if defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R)
>> [... 261 lines ...]
>> #else /* defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R) */
>> [... ~ 244 similar lines ...]
>> #endif /* _ALLBSD_SOURCE */
>>
>>
>> When the fix for https://bugs.openjdk.org/browse/JDK-8201369 was backported to `8`, the second branch of the large `#ifdef` in `Inet4AddressImpl.c` was not changed at the same time, which is incorrect, since reverse lookup should only ever happen on `Solaris`, according to the description of `JDK-8201369`.
>>
>> I used the `JDK 11` `unix/native/libnet/Inet4AddressImpl.c` implementation; after this change, the only difference between `11`'s `Java_java_net_Inet4AddressImpl_getLocalHostName` and the `defined(HAS_GLIBC_GETHOSTBY_R)` one will be the use of `JVM_GetHostName` in `8` versus `gethostname` in `11`.
>>
>> I decided to update the `hostlen` argument to `getnameinfo` from `NI_MAXHOST` to `sizeof(hostname)` to fix https://bugs.openjdk.org/browse/JDK-8202181 for this function. I do not have a `Solaris` machine to test on, but this matches `11`'s `getnameinfo` calls, and is correct given `hostname[NI_MAXHOST] = '\0'`.
>>
>> The resulting behaviour should be the same, other than the reverse lookup only being performed on `Solaris`.
>>
>> The implementations of `Java_java_net_Inet4AddressImpl_getLocalHostName` in each of the `#ifdef` branches diverge already because the fix for https://bugs.openjdk.org/browse/JDK-7112670 (https://github.com/openjdk/jdk8u-dev/commit/a62dd6282b7a0f1f3c75dad90385783b93d30e61) was only applied to the second branch.
>>
>> Probably the upper `Java_java_net_Inet4AddressImpl_getLocalHostName` implementation could be made identical to the lower, but I do not want to do that, just in case `NI_MAXHOST` is preferred to `sizeof(hostname)` on `!defined(HAS_GLIBC_GETHOSTBY_R)` operating systems.
>
> Thomas Fitzsimmons has updated the pull request incrementally with one additional commit since the last revision:
>
> Revert partial backport of JDK-8202181
Thanks. Happy for this to go in now it's just the backport.
Please [apply for approval](https://wiki.openjdk.org/display/SKARA/Pull+Request+Commands#PullRequestCommands-/approval)
-------------
Marked as reviewed by andrew (Reviewer).
PR Review: https://git.openjdk.org/jdk8u-dev/pull/661#pullrequestreview-2905479803
More information about the jdk8u-dev
mailing list