Skip to content

Commit 65c4a5d

Browse files
committed
Merge
2 parents 3647d98 + cc541e9 commit 65c4a5d

File tree

62 files changed

+2380
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2380
-703
lines changed

.hgtags

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,3 +1029,7 @@ b81aa0cb626746f790f4b6fdcc71d84d00eff136 jdk8u332-b01
10291029
7376b980d6b085d5d9061d212f3ad69d239718e6 jdk8u332-b03
10301030
f58fc9077d2274b2832bc00ff16d112fe99d9ace jdk8u332-b04
10311031
2a92df021686242bb55ecd324b5dee00c45a0a8e jdk8u332-b05
1032+
6d5c4e11830c154190021d6ae134c5f4162ff7cc jdk8u332-b06
1033+
6d526dbc3432fd9f2db19bdcb2f6b5b8799d88f0 jdk8u332-b07
1034+
95b31159fdfd496e521e119aba9ef54acf6b272e jdk8u332-b08
1035+
37aca7715d13acfdc931aab7dbcdd41f9fd4b042 jdk8u332-b09

jaxp/src/com/sun/java_cup/internal/runtime/lr_parser.java

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,8 @@
2626

2727
package com.sun.java_cup.internal.runtime;
2828

29+
import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;
30+
import java.util.Arrays;
2931
import java.util.Stack;
3032

3133
/** This class implements a skeleton table driven LR parser. In general,
@@ -134,9 +136,19 @@
134136
* @see com.sun.java_cup.internal.runtime.Symbol
135137
* @see com.sun.java_cup.internal.runtime.virtual_parse_stack
136138
* @author Frank Flannery
139+
*
140+
* @LastModified: Jan 2022
137141
*/
138142

139143
public abstract class lr_parser {
144+
public static final int ID_GROUP = 1;
145+
public static final int ID_OPERATOR = 2;
146+
public static final int ID_TOTAL_OPERATOR = 3;
147+
148+
private boolean isLiteral = false;
149+
private int grpCount = 0;
150+
private int opCount = 0;
151+
private int totalOpCount = 0;
140152

141153
/*-----------------------------------------------------------*/
142154
/*--- Constructor(s) ----------------------------------------*/
@@ -355,8 +367,34 @@ public void user_init() throws java.lang.Exception { }
355367
* the "scan with" clause. Do not recycle objects; every call to
356368
* scan() should return a fresh object.
357369
*/
358-
public Symbol scan() throws java.lang.Exception {
359-
return getScanner().next_token();
370+
public Symbol scan() throws Exception {
371+
Symbol s = getScanner().next_token();
372+
373+
if (s.sym == sym.LPAREN) {
374+
if (!isLiteral) {
375+
grpCount++;
376+
}
377+
opCount++; // function
378+
isLiteral = false;
379+
} else if (contains(sym.OPERATORS, s.sym)) {
380+
opCount++;
381+
isLiteral = false;
382+
}
383+
384+
if (s.sym == sym.Literal || s.sym == sym.QNAME) {
385+
isLiteral = true;
386+
}
387+
388+
return s;
389+
}
390+
391+
private boolean contains(final int[] arr, final int key) {
392+
for (int i = 0 ; i < arr.length ; ++i) {
393+
if (arr[i] == key) {
394+
return true;
395+
}
396+
}
397+
return false;
360398
}
361399

362400
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
@@ -552,6 +590,9 @@ public Symbol parse() throws java.lang.Exception
552590

553591
/* do user initialization */
554592
user_init();
593+
isLiteral = false;
594+
grpCount = 0;
595+
opCount = 0;
555596

556597
/* get the first token */
557598
cur_token = scan();
@@ -630,9 +671,29 @@ else if (act == 0)
630671
}
631672
}
632673
}
674+
675+
totalOpCount += opCount;
633676
return lhs_sym;
634677
}
635678

679+
/**
680+
* Returns the count of operators in XPath expressions.
681+
*
682+
* @param id the ID of the count
683+
* @return the count associated with the ID
684+
*/
685+
public int getCount(int id) {
686+
switch (id) {
687+
case ID_GROUP:
688+
return grpCount;
689+
case ID_OPERATOR:
690+
return opCount;
691+
case ID_TOTAL_OPERATOR:
692+
return totalOpCount;
693+
}
694+
return 0;
695+
}
696+
636697
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
637698

638699
/** Write a debugging message to System.err for the debugging version

jaxp/src/com/sun/org/apache/xalan/internal/XalanConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ public final class XalanConstants {
175175
*/
176176
public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
177177

178+
/**
179+
* JDK XPath Expression group limit
180+
*/
181+
public static final String XPATH_GROUP_LIMIT = "jdk.xml.xpathExprGrpLimit";
182+
183+
/**
184+
* JDK XPath Expression operators limit
185+
*/
186+
public static final String XPATH_OP_LIMIT = "jdk.xml.xpathExprOpLimit";
187+
188+
/**
189+
* JDK XSL XPath limit or Total Number of Operators Permitted in an XSL Stylesheet
190+
*/
191+
public static final String XPATH_TOTALOP_LIMIT = "jdk.xml.xpathTotalOpLimit";
192+
178193
//legacy System Properties
179194
public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
180195
public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,7 +24,7 @@
2424
import com.sun.org.apache.xalan.internal.XalanConstants;
2525
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
2626
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
27-
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
27+
import jdk.xml.internal.XMLSecurityManager;
2828
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
2929
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
3030
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
@@ -465,8 +465,10 @@ public SyntaxTreeNode parse(InputSource input) {
465465
XMLSecurityManager securityManager =
466466
(XMLSecurityManager) _xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
467467
for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
468-
lastProperty = limit.apiProperty();
469-
reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
468+
if (limit.isSupported(XMLSecurityManager.Processor.PARSER)) {
469+
lastProperty = limit.apiProperty();
470+
reader.setProperty(lastProperty, securityManager.getLimitValueAsString(limit));
471+
}
470472
}
471473
if (securityManager.printEntityCountInfo()) {
472474
lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
@@ -1121,6 +1123,9 @@ private SyntaxTreeNode parseTopLevel(SyntaxTreeNode parent, String text,
11211123
expression, parent));
11221124
}
11231125
catch (Exception e) {
1126+
if (ErrorMsg.XPATH_LIMIT.equals(e.getMessage())) {
1127+
throw new RuntimeException(ErrorMsg.XPATH_LIMIT);
1128+
}
11241129
if (_xsltc.debug()) e.printStackTrace();
11251130
reportError(ERROR, new ErrorMsg(ErrorMsg.XPATH_PARSER_ERR,
11261131
expression, parent));

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XPathParser.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import java.util.Stack;
1010
import java.util.Vector;
1111
import java.io.StringReader;
12+
import com.sun.org.apache.xalan.internal.XalanConstants;
13+
import jdk.xml.internal.XMLLimitAnalyzer;
14+
import jdk.xml.internal.XMLSecurityManager;
15+
import jdk.xml.internal.XMLSecurityManager.Limit;
1216
import com.sun.java_cup.internal.runtime.*;
1317
import com.sun.org.apache.xml.internal.dtm.DTM;
1418
import com.sun.org.apache.xalan.internal.xsltc.DOM;
@@ -20,9 +24,12 @@
2024
* CUP v0.11b generated parser.
2125
* This class was generated by CUP v0.11b on Nov 12, 2019.
2226
*
23-
* @LastModified: Nov 2019
27+
* @LastModified: Jan 2022
2428
*/
2529
public class XPathParser extends com.sun.java_cup.internal.runtime.lr_parser {
30+
private int grpLimit = 0;
31+
private int opLimit = 0;
32+
private int totalOpLimit = 0;
2633

2734
/** Default constructor. */
2835
public XPathParser() {
@@ -929,10 +936,19 @@ public int error_sym() {
929936
*/
930937
public SymbolTable _symbolTable;
931938

939+
private XMLSecurityManager _xmlSM;
940+
private XMLLimitAnalyzer _limitAnalyzer = null;
941+
932942
public XPathParser(Parser parser) {
933943
_parser = parser;
934944
_xsltc = parser.getXSLTC();
935945
_symbolTable = parser.getSymbolTable();
946+
_xmlSM = (XMLSecurityManager)_xsltc.getProperty(XalanConstants.SECURITY_MANAGER);
947+
_limitAnalyzer = new XMLLimitAnalyzer();
948+
// no limits if _xmlSM is null
949+
grpLimit = (_xmlSM != null) ? _xmlSM.getLimit(Limit.XPATH_GROUP_LIMIT) : 0;
950+
opLimit = (_xmlSM != null) ? _xmlSM.getLimit(Limit.XPATH_OP_LIMIT) : 0;
951+
totalOpLimit = (_xmlSM != null) ? _xmlSM.getLimit(Limit.XPATH_TOTALOP_LIMIT) : 0;
936952
}
937953

938954
public int getLineNumber() {
@@ -1078,7 +1094,32 @@ public Symbol parse(String expression, int lineNumber) throws Exception {
10781094
try {
10791095
_expression = expression;
10801096
_lineNumber = lineNumber;
1081-
return super.parse();
1097+
Symbol s = super.parse();
1098+
int grpCount = getCount(ID_GROUP);
1099+
int opCount = getCount(ID_OPERATOR);
1100+
int totalOpCount = getCount(ID_TOTAL_OPERATOR);
1101+
1102+
String errCode = null;
1103+
Object[] params = null;
1104+
if (grpLimit > 0 && grpCount > grpLimit) {
1105+
errCode = ErrorMsg.XPATH_GROUP_LIMIT;
1106+
params = new Object[]{grpCount, grpLimit,
1107+
_xmlSM.getStateLiteral(Limit.XPATH_GROUP_LIMIT)};
1108+
} else if (opLimit > 0 && opCount > opLimit) {
1109+
errCode = ErrorMsg.XPATH_OPERATOR_LIMIT;
1110+
params = new Object[]{opCount, opLimit,
1111+
_xmlSM.getStateLiteral(Limit.XPATH_OP_LIMIT)};
1112+
} else if (totalOpLimit > 0 && totalOpCount > totalOpLimit) {
1113+
errCode = ErrorMsg.XPATH_TOTAL_OPERATOR_LIMIT;
1114+
params = new Object[]{totalOpCount, totalOpLimit,
1115+
_xmlSM.getStateLiteral(Limit.XPATH_TOTALOP_LIMIT)};
1116+
}
1117+
if (errCode != null) {
1118+
_parser.reportError(Constants.FATAL,
1119+
new ErrorMsg(errCode, lineNumber, params));
1120+
throw new RuntimeException(ErrorMsg.XPATH_LIMIT);
1121+
}
1122+
return s;
10821123
} catch (IllegalCharException e) {
10831124
ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_CHAR_ERR,
10841125
lineNumber, e.getMessage());

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,7 +23,6 @@
2323
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
2424
import com.sun.org.apache.xalan.internal.XalanConstants;
2525
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
26-
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
2726
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
2827
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
2928
import com.sun.org.apache.xml.internal.dtm.DTM;
@@ -47,6 +46,7 @@
4746
import java.util.jar.Manifest;
4847
import javax.xml.XMLConstants;
4948
import jdk.xml.internal.JdkXmlFeatures;
49+
import jdk.xml.internal.XMLSecurityManager;
5050
import org.xml.sax.InputSource;
5151
import org.xml.sax.XMLReader;
5252

@@ -481,7 +481,10 @@ else if (systemId != null && !systemId.equals("")) {
481481
}
482482
}
483483
catch (Exception e) {
484-
/*if (_debug)*/ e.printStackTrace();
484+
if (_debug) e.printStackTrace();
485+
if (ErrorMsg.XPATH_LIMIT.equals(e.getMessage())) {
486+
return !_parser.errorsFound();
487+
}
485488
_parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
486489
}
487490
catch (Error e) {

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/sym.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package com.sun.org.apache.xalan.internal.xsltc.compiler;
88

9+
import java.util.Arrays;
10+
911
/** CUP generated class containing symbol constants. */
1012
public class sym {
1113
/* terminals */
@@ -63,4 +65,12 @@ public class sym {
6365
public static final int ATTRIBUTE = 41;
6466
public static final int GT = 19;
6567
public static final int NODE = 31;
68+
/*
69+
AXES: count once at DCOLON,
70+
these axes names are therefore not counted:
71+
NAMESPACE, FOLLOWINGSIBLING, CHILD, DESCENDANTORSELF, DESCENDANT
72+
, PRECEDINGSIBLING, SELF, ANCESTORORSELF, PRECEDING, ANCESTOROR, PARENT, FOLLOWING, ATTRIBUTE
73+
*/
74+
public static final int[] OPERATORS = {GE, SLASH, ATSIGN, LPAREN, DCOLON,
75+
MINUS, STAR, LT, OR, DIV, PLUS, LE, VBAR, MOD, EQ, LBRACK, DOLLAR, NE, GT};
6676
}

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMessages.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
/**
2626
* @author Morten Jorgensen
27+
* @LastModified: Jan 2022
2728
*/
2829
public class ErrorMessages extends ListResourceBundle {
2930

@@ -1011,12 +1012,22 @@ public Object[][] getContents()
10111012
"smaller templates."
10121013
},
10131014

1014-
{ErrorMsg.DESERIALIZE_TRANSLET_ERR, "When Java security is enabled, " +
1015-
"support for deserializing TemplatesImpl is disabled." +
1016-
"This can be overridden by setting the jdk.xml.enableTemplatesImplDeserialization" +
1017-
" system property to true."}
1018-
1019-
};
1015+
{ErrorMsg.DESERIALIZE_TRANSLET_ERR, "When Java security is enabled, "
1016+
+ "support for deserializing TemplatesImpl is disabled. This can be "
1017+
+ "overridden by setting the jdk.xml.enableTemplatesImplDeserialization"
1018+
+ " system property to true."},
1019+
1020+
{ErrorMsg.XPATH_GROUP_LIMIT,
1021+
"JAXP0801001: the compiler encountered an XPath expression containing "
1022+
+ "''{0}'' groups that exceeds the ''{1}'' limit set by ''{2}''."},
1023+
1024+
{ErrorMsg.XPATH_OPERATOR_LIMIT,
1025+
"JAXP0801002: the compiler encountered an XPath expression containing "
1026+
+ "''{0}'' operators that exceeds the ''{1}'' limit set by ''{2}''."},
1027+
{ErrorMsg.XPATH_TOTAL_OPERATOR_LIMIT,
1028+
"JAXP0801003: the compiler encountered XPath expressions with an accumulated "
1029+
+ "''{0}'' operators that exceeds the ''{1}'' limit set by ''{2}''."},
1030+
};
10201031

10211032
}
10221033
}

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ public final class ErrorMsg {
172172

173173
public static final String DESERIALIZE_TRANSLET_ERR = "DESERIALIZE_TEMPLATES_ERR";
174174

175+
public static final String XPATH_LIMIT = "XPATH_LIMIT";
176+
public static final String XPATH_GROUP_LIMIT = "XPATH_GROUP_LIMIT";
177+
public static final String XPATH_OPERATOR_LIMIT = "XPATH_OPERATOR_LIMIT";
178+
public static final String XPATH_TOTAL_OPERATOR_LIMIT = "XPATH_TOTAL_OPERATOR_LIMIT";
179+
175180
// All error messages are localized and are stored in resource bundles.
176181
// This array and the following 4 strings are read from that bundle.
177182
private static ResourceBundle _bundle;
@@ -208,7 +213,11 @@ public ErrorMsg(String message, int line) {
208213
public ErrorMsg(String code, int line, Object param) {
209214
_code = code;
210215
_line = line;
211-
_params = new Object[] { param };
216+
if (param instanceof Object[]) {
217+
_params = (Object[])param;
218+
} else {
219+
_params = new Object[] { param };
220+
}
212221
}
213222

214223
public ErrorMsg(String code, Object param) {

jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase.State;
2525
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
2626
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
27-
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
27+
import jdk.xml.internal.XMLSecurityManager;
2828
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager;
2929
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager.Property;
3030
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;

0 commit comments

Comments
 (0)