db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abr...@apache.org
Subject svn commit: r481117 - /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
Date Fri, 01 Dec 2006 00:19:28 GMT
Author: abrown
Date: Thu Nov 30 16:19:26 2006
New Revision: 481117

URL: http://svn.apache.org/viewvc?view=rev&rev=481117
Log:
DERBY-2131: Use a privileged block when calling out to the JAXP parser
so that users running with a security manager can insert XML values
that reference external DTDs without encountering security exceptions.

This patch does not include any tests; however, relevant test cases
will be enabled as part of DERBY-1758.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java?view=diff&rev=481117&r1=481116&r2=481117
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java Thu Nov 30
16:19:26 2006
@@ -307,12 +307,29 @@
      *   serialization.
      * @return A properly serialized version of xmlAsText.
      */
-    protected String serializeToString(String xmlAsText)
+    protected String serializeToString(final String xmlAsText)
         throws Exception
     {
-        ArrayList aList = new ArrayList();
-        aList.add(dBuilder.parse(
-            new InputSource(new StringReader(xmlAsText))));
+        final ArrayList aList = new ArrayList();
+
+        /* The call to dBuilder.parse() is a call to an external
+         * (w.r.t. to Derby) JAXP parser.  If the received XML
+         * text references an external DTD, then the JAXP parser
+         * will try to read that external DTD.  Thus we wrap the
+         * call to parse inside a privileged action to make sure
+         * that the JAXP parser has the required permissions for
+         * reading the DTD file.
+         */
+        java.security.AccessController.doPrivileged(
+            new java.security.PrivilegedExceptionAction()
+            {
+                public Object run() throws Exception
+                {
+                    aList.add(dBuilder.parse(
+                        new InputSource(new StringReader(xmlAsText))));
+                    return null;
+                }
+            });
 
         /* The second argument in the following call is for
          * catching cases where we have a top-level (parentless)



Mime
View raw message