Repository: hive
Updated Branches:
  refs/heads/master c7d7b1530 -> abede8ee2


Revert "HIVE-18789: Disallow embedded element in UDFXPathUtil (Daniel Dai, 
reviewed by Thejas Nair)"

This reverts commit 4b22fcbdaf31a2ff8c4bcf6d69ce3dcb8a363b82.


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/abede8ee
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/abede8ee
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/abede8ee

Branch: refs/heads/master
Commit: abede8ee251875ae06ce4cf26ed4e0928bb3634d
Parents: c7d7b15
Author: Daniel Dai <da...@hortonworks.com>
Authored: Tue Mar 6 14:07:12 2018 -0800
Committer: Daniel Dai <da...@hortonworks.com>
Committed: Tue Mar 6 14:07:12 2018 -0800

----------------------------------------------------------------------
 .../hadoop/hive/ql/udf/xml/UDFXPathUtil.java    | 31 +-------------------
 .../hive/ql/udf/xml/TestUDFXPathUtil.java       | 31 +-------------------
 2 files changed, 2 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/abede8ee/ql/src/java/org/apache/hadoop/hive/ql/udf/xml/UDFXPathUtil.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/xml/UDFXPathUtil.java 
b/ql/src/java/org/apache/hadoop/hive/ql/udf/xml/UDFXPathUtil.java
index 756a547..fbdd340 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/xml/UDFXPathUtil.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/xml/UDFXPathUtil.java
@@ -22,11 +22,7 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 
-import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpression;
@@ -42,13 +38,9 @@ import org.xml.sax.InputSource;
  * of this class.
  */
 public class UDFXPathUtil {
-  static final boolean DISABLE_XINCLUDE = true;
-  private DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-  private DocumentBuilder builder = null;
   private XPath xpath = XPathFactory.newInstance().newXPath();
   private ReusableStringReader reader = new ReusableStringReader();
   private InputSource inputSource = new InputSource(reader);
-
   private XPathExpression expression = null;
   private String oldPath = null;
 
@@ -74,33 +66,12 @@ public class UDFXPathUtil {
       return null;
     }
 
-    if (builder == null){
-      initializeDocumentBuilderFactory();
-      try {
-        builder = dbf.newDocumentBuilder();
-      } catch (ParserConfigurationException e) {
-        throw new RuntimeException("Error instantiating DocumentBuilder, 
cannot build xml parser", e);
-      }
-    }
-
     reader.set(xml);
 
     try {
-      return expression.evaluate(builder.parse(inputSource), qname);
+      return expression.evaluate(inputSource, qname);
     } catch (XPathExpressionException e) {
       throw new RuntimeException ("Invalid expression '" + oldPath + "'", e);
-    } catch (Exception e) {
-      throw new RuntimeException("Error loading expression '" + oldPath + "'", 
e);
-    }
-  }
-
-  private void initializeDocumentBuilderFactory() {
-
-    dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-    dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
-
-    if (DISABLE_XINCLUDE){
-      dbf.setXIncludeAware(false);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/abede8ee/ql/src/test/org/apache/hadoop/hive/ql/udf/xml/TestUDFXPathUtil.java
----------------------------------------------------------------------
diff --git 
a/ql/src/test/org/apache/hadoop/hive/ql/udf/xml/TestUDFXPathUtil.java 
b/ql/src/test/org/apache/hadoop/hive/ql/udf/xml/TestUDFXPathUtil.java
index b28ed63..2edcb7d 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/udf/xml/TestUDFXPathUtil.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/xml/TestUDFXPathUtil.java
@@ -20,15 +20,12 @@ package org.apache.hadoop.hive.ql.udf.xml;
 
 import javax.xml.xpath.XPathConstants;
 
-import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import static org.junit.Assert.*;
 
-import java.io.File;
-
 public class TestUDFXPathUtil {
 
   @Test
@@ -81,31 +78,5 @@ public class TestUDFXPathUtil {
     assertTrue(result instanceof NodeList);
     assertEquals(5, ((NodeList)result).getLength());
   }
-
-  @Test
-  public void testEmbedFailure() throws Exception {
-
-    String secretValue = String.valueOf(Math.random());
-    File tempFile = File.createTempFile("verifyembed", ".tmp");
-    tempFile.deleteOnExit();
-    String fname = tempFile.getAbsolutePath();
-
-    FileUtils.writeStringToFile(tempFile, secretValue);
-
-    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
-        "<!DOCTYPE test [ \n" +
-        "    <!ENTITY embed SYSTEM \"" + fname + "\"> \n" +
-        "]>\n" +
-        "<foo>&embed;</foo>";
-
-    String evaled = null;
-    Exception caught = null;
-    try {
-      evaled = new UDFXPathUtil().evalString(xml, "/foo");
-    } catch (Exception e){
-      caught = e;
-    }
-    assertTrue(caught.getCause().getMessage()
-      .contains("\'file\' access is not allowed due to restriction set by the 
accessExternalDTD property"));
-  }
+  
 }

Reply via email to