harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r477355 - in /harmony/enhanced: classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
Date Mon, 20 Nov 2006 21:40:15 GMT
Author: tellison
Date: Mon Nov 20 13:40:14 2006
New Revision: 477355

URL: http://svn.apache.org/viewvc?view=rev&rev=477355
Log:
Fix and regression test for threadLocal vulnerability.  ThreadLocalVariables should
not be asked for their hashCode and equality to prevent spoof implementations.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java?view=diff&rev=477355&r1=477354&r2=477355
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
Mon Nov 20 13:40:14 2006
@@ -98,6 +98,16 @@
 		assertTrue("ThreadLocal's initial value in other Thread should be "
 				+ INITIAL_VALUE, THREADVALUE.result == INITIAL_VALUE);
 
+        /* Regression test for implementation vulnerability reported
+         * on Harmony dev list.
+         */
+       ThreadLocal<Object> thrVar = new ThreadLocal<Object>() {
+           public int hashCode() {
+               fail("ThreadLocal should not be asked for it's hashCode");
+               return 0; // never reached
+           }
+       };
+       thrVar.get();
 	}
 
 	/**

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java?view=diff&rev=477355&r1=477354&r2=477355
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
Mon Nov 20 13:40:14 2006
@@ -23,6 +23,7 @@
 
 import java.security.AccessController;
 import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -906,7 +907,7 @@
      */
     void setThreadLocal(ThreadLocal<Object> local, Object value) {
         if (localValues == null) {
-            localValues = new HashMap<ThreadLocal<Object>, Object>();
+            localValues = new IdentityHashMap<ThreadLocal<Object>, Object>();
         }
         localValues.put(local, value);
     }
@@ -922,7 +923,7 @@
     Object getThreadLocal(ThreadLocal<Object> local) {
         Object value;
         if (localValues == null) {
-            localValues = new HashMap<ThreadLocal<Object>, Object>();
+            localValues = new IdentityHashMap<ThreadLocal<Object>, Object>();
             value = local.initialValue();
             localValues.put(local, value);
             return value;
@@ -969,7 +970,7 @@
         if (parentLocalValues == null) {
            return;
         }
-        localValues = new HashMap<ThreadLocal<Object>, Object>(parentLocalValues.size());
+        localValues = new IdentityHashMap<ThreadLocal<Object>, Object>(parentLocalValues.size());
         for (Iterator<ThreadLocal<Object>> it = parentLocalValues.keySet().iterator();
it.hasNext();) {
             ThreadLocal<Object> local = it.next();
             if (local instanceof InheritableThreadLocal) {



Mime
View raw message