From f1f76ba4975c311039a2cd555f8f3c38f8acc1d6 Mon Sep 17 00:00:00 2001 From: chegar Date: Wed, 1 May 2013 10:03:39 +0100 Subject: [PATCH] 6594296: NetworkInterface.getHardwareAddress returns zero length byte array Reviewed-by: alanb --- src/windows/native/java/net/NetworkInterface_winXP.c | 10 ++++++---- test/java/net/NetworkInterface/Test.java | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/windows/native/java/net/NetworkInterface_winXP.c b/src/windows/native/java/net/NetworkInterface_winXP.c index ce0206be0..1078d826a 100644 --- a/src/windows/native/java/net/NetworkInterface_winXP.c +++ b/src/windows/native/java/net/NetworkInterface_winXP.c @@ -818,10 +818,12 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP ptr = getAdapter(env, index); if (ptr != NULL) { len = ptr->PhysicalAddressLength; - ret = (*env)->NewByteArray(env, len); - if (!IS_NULL(ret)) { - (*env)->SetByteArrayRegion(env, ret, 0, len, - (jbyte*) ptr->PhysicalAddress); + if (len > 0) { + ret = (*env)->NewByteArray(env, len); + if (!IS_NULL(ret)) { + (*env)->SetByteArrayRegion(env, ret, 0, len, + (jbyte*) ptr->PhysicalAddress); + } } free(ptr); } diff --git a/test/java/net/NetworkInterface/Test.java b/test/java/net/NetworkInterface/Test.java index 70b9201d7..74033c195 100644 --- a/test/java/net/NetworkInterface/Test.java +++ b/test/java/net/NetworkInterface/Test.java @@ -21,9 +21,9 @@ * questions. */ -/* @test 01/02/14 - * @bug 4405354 - * @summary Exercise java.net.NetworkInterface +/* @test + * @bug 4405354 6594296 + * @summary Basic tests for NetworkInterface */ import java.net.NetworkInterface; import java.net.InetAddress; @@ -69,6 +69,12 @@ public class Test { throw new Exception("hashCode contract broken"); } System.out.println("hashCode() test passed."); + + byte[] ba = ni.getHardwareAddress(); + if (ba != null && ba.length == 0) { + throw new Exception("getHardwareAddress returned 0 length byte array"); + } + System.out.println("getHardwareAddress() test passed."); } // misc tests :- -- GitLab