RFR: 8275640 (win) java.net.NetworkInterface issues with IPv6-only environments [v6]

Daniel Fuchs dfuchs at openjdk.java.net
Wed Jan 26 18:52:48 UTC 2022


On Wed, 19 Jan 2022 08:15:24 GMT, Daniel Jeliński <djelinski at openjdk.org> wrote:

>> Clean up of various issues related to error handling and memory management
>
> Daniel Jeliński has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 12 additional commits since the last revision:
> 
>  - Fix invalid free
>  - Merge remote-tracking branch 'origin' into interface-cleanup
>  - Remove redundant initialization
>  - Remove unused / incorrect exit code -2 from enumInterfaces
>  - Address problems reported by clang-tidy
>  - Restore support for IPv6-only operation
>  - Fix memory leak
>  - Fixup getAllInterfacesAndAddresses
>  - Fixup getAddrsFromAdapter
>  - Fixup enumAddresses_win
>  - ... and 2 more: https://git.openjdk.java.net/jdk/compare/15024daa...98b40812

src/java.base/windows/native/libnet/NetworkInterface_winXP.c line 253:

> 251: 
> 252:     ret = enumInterfaces(env, netifPP);
> 253:     if (ret < 0) {

Why did we remove handling for -2 here when `enumInterfaces` might return -2 if it does not find any IPv4 network interface? Shouldn't we keep the code that reset the exception status and set *netifPP = null here if ret == -2?

src/java.base/windows/native/libnet/NetworkInterface_winXP.c line 271:

> 269:     ret = lookupIPAddrTable(env, &tableP);
> 270:     if (ret == -1) {
> 271:       free_netif(*netifPP);

*netifPP might be null here.

src/java.base/windows/native/libnet/NetworkInterface_winXP.c line 280:

> 278:         tableP = NULL;
> 279:     }
> 280:     while (curr != NULL) {

Maybe we should not enter here if tableP == null. Looks like it should be `while ( curr != NULL && tableP != null)` - either that or guard the block with an `if (tableP != NULL)` ?

src/java.base/windows/native/libnet/NetworkInterface_winXP.c line 297:

> 295:     flags = GAA_FLAG_SKIP_DNS_SERVER;
> 296:     flags |= GAA_FLAG_SKIP_MULTICAST;
> 297:     flags |= GAA_FLAG_INCLUDE_PREFIX;

tableP could be null at lime 293 - `free(tableP)` should be guarded by a null check

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

PR: https://git.openjdk.java.net/jdk/pull/6090


More information about the net-dev mailing list