[jdk8u-dev] Integrated: 8339414: Fix JDK-8202369 incorrect backport for 8u

Thomas Fitzsimmons duke at openjdk.org
Mon Jun 16 23:06:37 UTC 2025


On Wed, 4 Jun 2025 20:44:19 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.

This pull request has now been integrated.

Changeset: 51b63079
Author:    Thomas Fitzsimmons <fitzsim at redhat.com>
Committer: Andrew John Hughes <andrew at openjdk.org>
URL:       https://git.openjdk.org/jdk8u-dev/commit/51b6307937d9584f8690e4916444e479eeafff28
Stats:     26 lines in 1 file changed: 9 ins; 13 del; 4 mod

8339414: Fix JDK-8202369 incorrect backport for 8u

Reviewed-by: andrew

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

PR: https://git.openjdk.org/jdk8u-dev/pull/661


More information about the jdk8u-dev mailing list