commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1407867 - in /commons/proper/email/trunk/src: changes/changes.xml java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
Date Sat, 10 Nov 2012 18:20:56 GMT
Author: tn
Date: Sat Nov 10 18:20:55 2012
New Revision: 1407867

URL: http://svn.apache.org/viewvc?rev=1407867&view=rev
Log:
[EMAIL-116] Prevent external modification of internal array in DataSourceCompositeResolver.

Modified:
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1407867&r1=1407866&r2=1407867&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Sat Nov 10 18:20:55 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="1.3" date="as in SVN">
+      <action dev="tn" type="fix" issue="EMAIL-116" date="2012-11-10" due-to="sebb">
+        Prevent external modification of internal array in DataSourceCompositeResolver.
+      </action>
       <action dev="tn" type="fix" issue="EMAIL-120" date="2012-11-07" due-to="Mike Bell">
         Close temporary input stream in MultiPartEmail#attach(DataSource, String, String)
         to prevent locking of file resources on windows systems.

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java?rev=1407867&r1=1407866&r2=1407867&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java
(original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java
Sat Nov 10 18:20:55 2012
@@ -63,7 +63,10 @@ public class DataSourceCompositeResolver
      */
     public DataSourceResolver[] getDataSourceResolvers()
     {
-        return dataSourceResolvers;
+        // clone the internal array to prevent external modification (see EMAIL-116)
+        final DataSourceResolver[] resolvers = new DataSourceResolver[dataSourceResolvers.length];
+        System.arraycopy(dataSourceResolvers, 0, resolvers, 0, dataSourceResolvers.length);
+        return resolvers;
     }
 
     public DataSource resolve(String resourceLocation) throws IOException

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java?rev=1407867&r1=1407866&r2=1407867&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
(original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
Sat Nov 10 18:20:55 2012
@@ -71,6 +71,24 @@ public class DataSourceCompositeResolver
         }
     }
 
+    public void testExternalModification() throws Exception
+    {
+        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"),
false);
+        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images",
false);
+        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver,
classPathResolver };
+        DataSourceCompositeResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers,
true);
+
+        DataSourceResolver[] arr = dataSourceResolver.getDataSourceResolvers();
+        
+        // modify an element in the returned array
+        arr[0] = null;
+        
+        DataSourceResolver[] arr2 = dataSourceResolver.getDataSourceResolvers();
+        
+        // assert that the external modification is not propagated to the internal array
+        assertNotNull(arr2[0]);        
+    }
+
     private byte[] toByteArray(DataSource dataSource) throws IOException
     {
         if(dataSource != null)



Mime
View raw message