From 6173b98ff1b0b487b0767823c234bbdb72c5bf64 Mon Sep 17 00:00:00 2001 From: chegar Date: Fri, 12 Sep 2014 15:51:22 +0100 Subject: [PATCH] 8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack Reviewed-by: michaelm --- src/windows/native/java/net/NetworkInterface.c | 8 +++++--- test/java/net/NetworkInterface/Test.java | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/windows/native/java/net/NetworkInterface.c b/src/windows/native/java/net/NetworkInterface.c index c436e8669..6483f1261 100644 --- a/src/windows/native/java/net/NetworkInterface.c +++ b/src/windows/native/java/net/NetworkInterface.c @@ -1014,9 +1014,11 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0 case MIB_IF_TYPE_FDDI: case IF_TYPE_IEEE80211: len = ifRowP->dwPhysAddrLen; - ret = (*env)->NewByteArray(env, len); - if (!IS_NULL(ret)) { - (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr); + if (len > 0) { + ret = (*env)->NewByteArray(env, len); + if (!IS_NULL(ret)) { + (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr); + } } break; } diff --git a/test/java/net/NetworkInterface/Test.java b/test/java/net/NetworkInterface/Test.java index 66ecbed56..56325fdae 100644 --- a/test/java/net/NetworkInterface/Test.java +++ b/test/java/net/NetworkInterface/Test.java @@ -22,7 +22,9 @@ */ /* @test - * @bug 4405354 6594296 + * @bug 4405354 6594296 8058216 + * @run main Test + * @run main/othervm -Djava.net.preferIPv4Stack=true Test * @summary Basic tests for NetworkInterface */ import java.net.NetworkInterface; -- GitLab