# HG changeset patch
# User michaelm
# Date 1280137222 -3600
# Node ID 7fe7aa39b5dcd501d49e88c1d5f672ca45af8658
# Parent  1f9e4b58a1f94bde7942b8caea4522c75d4f2180
6952603: NetworkInterface reveals local network address to untrusted code
Reviewed-by: chegar

diff --git a/src/share/classes/java/net/NetworkInterface.java b/src/share/classes/java/net/NetworkInterface.java
--- openjdk.orig/jdk/src/share/classes/java/net/NetworkInterface.java
+++ openjdk/jdk/src/share/classes/java/net/NetworkInterface.java
@@ -393,6 +393,10 @@ public final class NetworkInterface {
      * @since 1.6
      */
     public byte[] getHardwareAddress() throws SocketException {
+        if (!getInetAddresses().hasMoreElements()) {
+            // don't have connect permission to any local address
+            return null;
+        }
         for (InetAddress addr : addrs) {
             if (addr instanceof Inet4Address) {
                 return getMacAddr0(((Inet4Address)addr).getAddress(), name, index);
@@ -509,11 +513,10 @@ public final class NetworkInterface {
     }
 
     public int hashCode() {
-        int count = 0;
-        if (addrs != null) {
-            for (int i = 0; i < addrs.length; i++) {
-                count += addrs[i].hashCode();
-            }
+        int count = name == null? 0: name.hashCode();
+        Enumeration<InetAddress> addrs = getInetAddresses();
+        while (addrs.hasMoreElements()) {
+            count += addrs.nextElement().hashCode();
         }
         return count;
     }
