db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abr...@apache.org
Subject svn commit: r482837 - /db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
Date Wed, 06 Dec 2006 00:14:25 GMT
Author: abrown
Date: Tue Dec  5 16:14:23 2006
New Revision: 482837

URL: http://svn.apache.org/viewvc?view=rev&rev=482837
Log:
DERBY-2131: Porting changes from trunk to 10.2.

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.

svn merge -r 481116:481117 https://svn.apache.org/repos/asf/db/derby/code/trunk
svn merge -r 482302:482303 https://svn.apache.org/repos/asf/db/derby/code/trunk

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

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java?view=diff&rev=482837&r1=482836&r2=482837
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java Tue
Dec  5 16:14:23 2006
@@ -311,8 +311,41 @@
         throws Exception
     {
         ArrayList aList = new ArrayList();
-        aList.add(dBuilder.parse(
-            new InputSource(new StringReader(xmlAsText))));
+
+        /* 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.
+         */
+        try {
+
+            final InputSource is = new InputSource(new StringReader(xmlAsText));
+            aList.add(java.security.AccessController.doPrivileged(
+                new java.security.PrivilegedExceptionAction()
+                {
+                    public Object run() throws IOException, SAXException
+                    {
+                        return dBuilder.parse(is);
+                    }
+                }));
+
+        } catch (java.security.PrivilegedActionException pae) {
+
+            /* Unwrap the privileged exception so that the user can
+             * see what the underlying error is. For example, it could
+             * be an i/o error from parsing the XML value, which can
+             * happen if the XML value references an external DTD file
+             * but the JAXP parser hits an i/o error when trying to read
+             * the DTD.  In that case we want to throw the i/o error
+             * itself so that it does not appear as a security exception
+             * to the user.
+             */
+            throw pae.getException();
+
+        }
 
         /* The second argument in the following call is for
          * catching cases where we have a top-level (parentless)



Mime
View raw message