提交 f1f76ba4 编写于 作者: C chegar

6594296: NetworkInterface.getHardwareAddress returns zero length byte array

Reviewed-by: alanb
上级 0643f6c8
...@@ -818,10 +818,12 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP ...@@ -818,10 +818,12 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
ptr = getAdapter(env, index); ptr = getAdapter(env, index);
if (ptr != NULL) { if (ptr != NULL) {
len = ptr->PhysicalAddressLength; len = ptr->PhysicalAddressLength;
ret = (*env)->NewByteArray(env, len); if (len > 0) {
if (!IS_NULL(ret)) { ret = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, ret, 0, len, if (!IS_NULL(ret)) {
(jbyte*) ptr->PhysicalAddress); (*env)->SetByteArrayRegion(env, ret, 0, len,
(jbyte*) ptr->PhysicalAddress);
}
} }
free(ptr); free(ptr);
} }
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
* questions. * questions.
*/ */
/* @test 01/02/14 /* @test
* @bug 4405354 * @bug 4405354 6594296
* @summary Exercise java.net.NetworkInterface * @summary Basic tests for NetworkInterface
*/ */
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.InetAddress; import java.net.InetAddress;
...@@ -69,6 +69,12 @@ public class Test { ...@@ -69,6 +69,12 @@ public class Test {
throw new Exception("hashCode contract broken"); throw new Exception("hashCode contract broken");
} }
System.out.println("hashCode() test passed."); 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 :- // misc tests :-
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册