8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures
authormsheppar
Mon, 09 Mar 2015 18:48:40 +0000
changeset 29376 ff7f17f3e2da
parent 29375 a20cc834d64f
child 29377 d3f457ce9c48
8065078: NetworkInterface.getNetworkInterfaces() triggers intermittent test failures Reviewed-by: chegar
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 <winsock2.h>           /* needed for htonl */
 #include <iprtrmib.h>
 #include <assert.h>
+#include <limits.h>
 
 #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);
     }