This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 482edcffcc Improve handling of stack overflow errors when parsing EL expressions. 482edcffcc is described below commit 482edcffcc0f7f18cc1d00a86c40f8d0b942faf0 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Aug 18 17:33:01 2022 +0100 Improve handling of stack overflow errors when parsing EL expressions. --- java/org/apache/el/ExpressionFactoryImpl.java | 5 +++ java/org/apache/el/lang/ExpressionBuilder.java | 6 ++- java/org/apache/el/util/ExceptionUtils.java | 56 ++++++++++++++++++++++++++ webapps/docs/changelog.xml | 8 ++++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/java/org/apache/el/ExpressionFactoryImpl.java b/java/org/apache/el/ExpressionFactoryImpl.java index 4bd8fc374e..6ab309e374 100644 --- a/java/org/apache/el/ExpressionFactoryImpl.java +++ b/java/org/apache/el/ExpressionFactoryImpl.java @@ -25,6 +25,7 @@ import javax.el.ValueExpression; import org.apache.el.lang.ELSupport; import org.apache.el.lang.ExpressionBuilder; import org.apache.el.stream.StreamELResolverImpl; +import org.apache.el.util.ExceptionUtils; import org.apache.el.util.MessageFactory; @@ -35,6 +36,10 @@ import org.apache.el.util.MessageFactory; */ public class ExpressionFactoryImpl extends ExpressionFactory { + static { + ExceptionUtils.preload(); + } + @Override public Object coerceToType(Object obj, Class<?> type) { return ELSupport.coerceToType(null, obj, type); diff --git a/java/org/apache/el/lang/ExpressionBuilder.java b/java/org/apache/el/lang/ExpressionBuilder.java index f383bccd41..bcd745e530 100644 --- a/java/org/apache/el/lang/ExpressionBuilder.java +++ b/java/org/apache/el/lang/ExpressionBuilder.java @@ -41,6 +41,7 @@ import org.apache.el.parser.ELParser; import org.apache.el.parser.Node; import org.apache.el.parser.NodeVisitor; import org.apache.el.util.ConcurrentCache; +import org.apache.el.util.ExceptionUtils; import org.apache.el.util.MessageFactory; /** @@ -145,9 +146,10 @@ public final class ExpressionBuilder implements NodeVisitor { n = n.jjtGetChild(0); } expressionCache.put(expr, n); - } catch (Exception e) { + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); throw new ELException( - MessageFactory.get("error.parseFail", expr), e); + MessageFactory.get("error.parseFail", expr), t); } finally { if (parser != null) { parserCache.push(parser); diff --git a/java/org/apache/el/util/ExceptionUtils.java b/java/org/apache/el/util/ExceptionUtils.java new file mode 100644 index 0000000000..d8a76ff184 --- /dev/null +++ b/java/org/apache/el/util/ExceptionUtils.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.el.util; + +/** + * Utilities for handling Throwables and Exceptions. + */ +/* + * Copied from o.a.t.u.ExceptionUtils + */ +public class ExceptionUtils { + + /** + * Checks whether the supplied Throwable is one that needs to be + * rethrown and swallows all others. + * @param t the Throwable to check + */ + public static void handleThrowable(Throwable t) { + if (t instanceof ThreadDeath) { + throw (ThreadDeath) t; + } + if (t instanceof StackOverflowError) { + // Swallow silently - it should be recoverable + return; + } + if (t instanceof VirtualMachineError) { + throw (VirtualMachineError) t; + } + // All other instances of Throwable will be silently swallowed + } + + + /** + * NO-OP method provided to enable simple pre-loading of this class. Since + * the class is used extensively in error handling, it is prudent to + * pre-load it to avoid any failure to load this class masking the true + * problem during error handling. + */ + public static void preload() { + // NO-OP + } +} diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 80de61c8e3..6b624b08c3 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -114,6 +114,14 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + Improve handling of stack overflow errors when parsing EL expressions. + (markt) + </fix> + </changelog> + </subsection> <subsection name="Other"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org