RFR(XS): 8202181: Correctly specify size of hostname buffer in Unix Inet*AddressImpl_getLocalHostName implementations

vyom tewari vyom.tewari at oracle.com
Tue Apr 24 10:24:31 UTC 2018



On Tuesday 24 April 2018 03:08 PM, Langer, Christoph wrote:
>
> Hi,
>
> please help reviewing a small change that I stumbled over when looking 
> into the getLocalHostName implementation. I found that the length of 
> the hostname buffer is not correctly passed to sub functions. The 
> buffer size is specified as “NI_MAXHOST + 1”, so this size should be 
> handed down to gethostname() and getnameinfo() calls, not just 
> NI_MAXHOST. I also moved the solaris #ifdefs into the else clause to 
> spare a few lines of code.
>
I think, it is intentional to handle case where return "hostname" is to 
large to fit in  array.  if you see the man 
page(http://man7.org/linux/man-pages/man2/gethostname.2.html) it says 
that it is unspecified whether returned buffer includes a terminating 
null byte.

current code will put null in case of large "hostname", What do you think ?

Thanks,
Vyom
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-8202181 
> <https://bugs.openjdk.java.net/browse/JDK-8202181>
>
> Webrev: http://cr.openjdk.java.net/~clanger/webrevs/8202181.0/ 
> <http://cr.openjdk.java.net/%7Eclanger/webrevs/8202181.0/>
>
> Thanks
>
> Christoph
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20180424/23c4541f/attachment.html>


More information about the net-dev mailing list