# HG changeset patch # User msheppar # Date 1425926920 0 # Node ID ff7f17f3e2da492d7dd07468eb9573ac26df5fc9 # Parent a20cc834d64f6dcbca6427b911c5bc5ce85cc66e 8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures Reviewed-by: chegar diff -r a20cc834d64f -r ff7f17f3e2da jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c --- a/jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c Mon Mar 09 16:18:33 2015 +0100 +++ b/jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c Mon Mar 09 18:48:40 2015 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,7 @@ #include /* needed for htonl */ #include #include +#include #include "java_net_NetworkInterface.h" #include "jni_util.h" @@ -70,7 +71,7 @@ #endif -static int bufsize = 1024; +static int bufsize = 4096; /* * return an array of IP_ADAPTER_ADDRESSES containing one element @@ -102,7 +103,11 @@ ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len); if (ret == ERROR_BUFFER_OVERFLOW) { - IP_ADAPTER_ADDRESSES * newAdapterInfo = + IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL; + if (len < (ULONG_MAX - bufsize)) { + len = len + bufsize; + } + newAdapterInfo = (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len); if (newAdapterInfo == NULL) { free(adapterInfo); @@ -113,7 +118,6 @@ adapterInfo = newAdapterInfo; - bufsize = len; ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len); } @@ -176,7 +180,11 @@ flags |= GAA_FLAG_INCLUDE_PREFIX; val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len); if (val == ERROR_BUFFER_OVERFLOW) { - IP_ADAPTER_ADDRESSES * newAdapterInfo = + IP_ADAPTER_ADDRESSES * newAdapterInfo = NULL; + if (len < (ULONG_MAX - bufsize)) { + len = len + bufsize; + } + newAdapterInfo = (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len); if (newAdapterInfo == NULL) { free(adapterInfo); @@ -187,7 +195,6 @@ adapterInfo = newAdapterInfo; - bufsize = len; val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len); }