RFR: 8327621: Check return value of uname in os::get_host_name
Johan Sjölen
jsjolen at openjdk.org
Fri Mar 8 12:23:52 UTC 2024
On Fri, 8 Mar 2024 02:56:41 GMT, David Holmes <dholmes at openjdk.org> wrote:
> Error checking in general is a good thing but in this case there are no specified failure modes for uname under Posix, and for Linux the only potential error is
>
> ```
> EFAULT buf is not valid
> ```
>
> which is obviously not a concern in the code we have.
>
> Did you encounter an error or was this just defensive programming?
This is simply defensive programming. I don't know what the potential issues could be on OSX or Solaris.
> _Mailing list message from [Peter Tribble](mailto:peter.tribble at gmail.com) on [hotspot-runtime-dev](mailto:hotspot-runtime-dev at mail.openjdk.org):_
>
> On Thu, Mar 7, 2024 at 6:29?PM Johan Sj?len <jsjolen at openjdk.org> wrote:
>
> > Hi,
> > Trivial bug fix where we didn't check the return value of `uname(2)` on
> > POSIX platforms. I checked callers of `get_host_name` and all wrap the
> > calls in an `if` branch so they already handle failures.
>
> I notice you're checking for a return value of zero. Posix 1003.1 states something like
>
> Upon successful completion, a non-negative value is returned. Otherwise, ?1 is returned and errno is set to indicate the error.
>
> So the correct check based on that would be != -1.
>
> Linux and FreeBSD document returning 0 on success, but Solaris/illumos definitely returns 1 (and as the port maintainer there it would be nice to have this correct). I don't have an AIX box right now but the existing uname(2) check within openjdk is for -1, eg https://github.com/openjdk/jdk/blob/master/src/hotspot/os/aix/os_aix.cpp#L2799
>
> Thanks,
>
> -- -Peter Tribble http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://mail.openjdk.org/pipermail/hotspot-runtime-dev/attachments/20240307/dfa31b6a/attachment.htm>
Thanks for the details Peter, I'll change the comparison as requested.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18157#issuecomment-1985599796
More information about the hotspot-runtime-dev
mailing list