aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoehw <unknown>2019-05-21 13:02:22 -0700
committerbell-sw <liberica@bell-sw.com>2019-10-23 16:22:35 +0300
commit4e64ac8131966dcbbf8c761bef61ada508ec2058 (patch)
tree33137740c55f116960c3edb2e5c311d0ae175b09
parentf1575e9b8a8d246785bee69206301696aabe43aa (diff)
downloadjdk8u_jaxp-4e64ac8131966dcbbf8c761bef61ada508ec2058.tar.gz
8223505: Better pattern compilation
Reviewed-by: rriggs, lancea, dfuchs, mschoene
-rw-r--r--src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java22
-rw-r--r--src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java9
2 files changed, 24 insertions, 7 deletions
diff --git a/src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java b/src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java
index 1b55599..bd19dff 100644
--- a/src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java
+++ b/src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
@@ -37,6 +36,7 @@ import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
* Tokenizes and parses XPath expressions. This should really be named
* XPathParserImpl, and may be renamed in the future.
* @xsl.usage general
+ * @LastModified: May 2019
*/
public class XPathParser
{
@@ -74,6 +74,9 @@ public class XPathParser
protected final static int FILTER_MATCH_PRIMARY = 1;
protected final static int FILTER_MATCH_PREDICATES = 2;
+ // counts open predicates
+ private int countPredicate;
+
/**
* The parser constructor.
*/
@@ -160,6 +163,9 @@ public class XPathParser
}
else
throw e;
+ } catch (StackOverflowError sof) {
+ error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN,
+ new Object[]{m_token, m_queueMark, countPredicate});
}
compiler.shrink();
@@ -193,7 +199,12 @@ public class XPathParser
m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);
nextToken();
- Pattern();
+ try {
+ Pattern();
+ } catch (StackOverflowError sof) {
+ error(XPATHErrorResources.ER_PREDICATE_TOO_MANY_OPEN,
+ new Object[]{m_token, m_queueMark, countPredicate});
+ }
if (null != m_token)
{
@@ -789,7 +800,7 @@ public class XPathParser
*/
protected void Expr() throws javax.xml.transform.TransformerException
{
- OrExpr();
+ OrExpr();
}
/**
@@ -1931,11 +1942,12 @@ public class XPathParser
*/
protected void Predicate() throws javax.xml.transform.TransformerException
{
-
if (tokenIs('['))
{
+ countPredicate++;
nextToken();
PredicateExpr();
+ countPredicate--;
consumeExpected(']');
}
}
diff --git a/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java b/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
index f96561b..12a5841 100644
--- a/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
+++ b/src/com/sun/org/apache/xpath/internal/res/XPATHErrorResources.java
@@ -1,6 +1,5 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1999-2005 The Apache Software Foundation.
@@ -30,6 +29,7 @@ import java.util.ListResourceBundle;
* Also you need to update the count of messages(MAX_CODE)or
* the count of warnings(MAX_WARNING) [ Information purpose only]
* @xsl.usage advanced
+ * @LastModified: May 2019
*/
public class XPATHErrorResources extends ListResourceBundle
{
@@ -147,6 +147,8 @@ public class XPATHErrorResources extends ListResourceBundle
"ER_FOUND_COMMA_BUT_NO_FOLLOWING_ARG";
public static final String ER_PREDICATE_ILLEGAL_SYNTAX =
"ER_PREDICATE_ILLEGAL_SYNTAX";
+ public static final String ER_PREDICATE_TOO_MANY_OPEN =
+ "ER_PREDICATE_TOO_MANY_OPEN";
public static final String ER_ILLEGAL_AXIS_NAME = "ER_ILLEGAL_AXIS_NAME";
public static final String ER_UNKNOWN_NODETYPE = "ER_UNKNOWN_NODETYPE";
public static final String ER_PATTERN_LITERAL_NEEDS_BE_QUOTED =
@@ -458,6 +460,9 @@ public static final String ER_IGNORABLE_WHITESPACE_NOT_HANDLED =
{ ER_PREDICATE_ILLEGAL_SYNTAX,
"'..[predicate]' or '.[predicate]' is illegal syntax. Use 'self::node()[predicate]' instead."},
+ { ER_PREDICATE_TOO_MANY_OPEN,
+ "Stack overflow while parsing {0} at {1}. Too many open predicates {2}."},
+
{ ER_ILLEGAL_AXIS_NAME,
"illegal axis name: {0}"},