RFR: 8170544: Fix code scan findings in libnet

Langer, Christoph christoph.langer at sap.com
Wed Jan 11 15:50:03 UTC 2017


Hi Chris,

thanks for looking.

> 1) NetworkInterface.c
> 
>     I’m not sure that the close is really necessary, since a JNI pending
>     exception can only be thrown is sock is less than 0. I think just
>     removing the ' && (*env)->ExceptionOccurred(env)’ from the original
>     if statement should be sufficient, no?

I think you are right. An exception can only occur if socket is less than 0. There is one case where socket could be less than 0 and no exception occurred. In that case we'd probably see an exception later on. But I think it would be fine to return NULL in case socket is < 0. Generally, this coding needs to be revisited in order to make it work for IPv6 only systems. We should do that when finishing up bug 8148424 [1].

> 2) net_util.c
> 
>     getInet6Address_scopeid_set should CHECK_NULL_RETURN(holder, JNI_FALSE)?
>     getInet6Address_scopeid now returns an unsigned in, why CHECK_NULL_RETURN(holder, -1)?
> 
>     Some of this, existing, code seems a little dubious.
> 

Good catch. The CHECK_NULL_RETURN macros need adaption. The reason why getInet6Address_scopeid should return unsigned int is that the struct sockaddr_in6 is also using unsigned int for the scope, e.g. on Linux [2] or Windows [3].

I've addressed your points in http://cr.openjdk.java.net/~clanger/webrevs/8170544.2/ Would you want to run this through JPRT again?

I would go and push it towards the end of the week.

Best regards
Christoph

[1] https://bugs.openjdk.java.net/browse/JDK-8148424
[2] http://man7.org/linux/man-pages/man7/ipv6.7.html
[3] https://msdn.microsoft.com/en-us/library/windows/hardware/ff570824(v=vs.85).aspx




More information about the net-dev mailing list