Minor follow-up changes to PR #371

- added some additional exclusions in struts-default.xml.
- added log warning that specifies the value of maxLength involved if
  applyExpressionMaxLength(maxLength) fails.
- added null guards to two handleOgnlException() methods that could
  result in an NPE with #371 changes (a null OgnlException parameter
  was permissible previously, correct or not).
This commit is contained in:
JCgH4164838Gh792C124B5
2019-11-02 13:31:09 -04:00
parent 13cfba86f8
commit e2b644a4fb
3 changed files with 16 additions and 7 deletions
@@ -189,11 +189,16 @@ public class OgnlUtil {
*/ */
@Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_MAX_LENGTH, required = false) @Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_MAX_LENGTH, required = false)
protected void applyExpressionMaxLength(String maxLength) { protected void applyExpressionMaxLength(String maxLength) {
if (maxLength == null || maxLength.isEmpty()) { try {
// user is going to disable this functionality if (maxLength == null || maxLength.isEmpty()) {
Ognl.applyExpressionMaxLength(null); // user is going to disable this functionality
} else { Ognl.applyExpressionMaxLength(null);
Ognl.applyExpressionMaxLength(Integer.parseInt(maxLength)); } else {
Ognl.applyExpressionMaxLength(Integer.parseInt(maxLength));
}
} catch (Exception ex) {
LOG.warn("Unable to set OGNL Expression Max Length {}.", maxLength); // Help configuration debugging.
throw ex;
} }
} }
@@ -204,7 +204,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
} }
protected void handleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, OgnlException e) { protected void handleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, OgnlException e) {
if (e.getReason() instanceof SecurityException) { if (e != null && e.getReason() instanceof SecurityException) {
LOG.warn("Could not evaluate this expression due to security constraints: [{}]", expr, e); LOG.warn("Could not evaluate this expression due to security constraints: [{}]", expr, e);
} }
boolean shouldLog = shouldLogMissingPropertyWarning(e); boolean shouldLog = shouldLogMissingPropertyWarning(e);
@@ -330,7 +330,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
protected Object handleOgnlException(String expr, boolean throwExceptionOnFailure, OgnlException e) { protected Object handleOgnlException(String expr, boolean throwExceptionOnFailure, OgnlException e) {
Object ret = null; Object ret = null;
if (e.getReason() instanceof SecurityException) { if (e != null && e.getReason() instanceof SecurityException) {
LOG.warn("Could not evaluate this expression due to security constraints: [{}]", expr, e); LOG.warn("Could not evaluate this expression due to security constraints: [{}]", expr, e);
} else { } else {
ret = findInContext(expr); ret = findInContext(expr);
@@ -45,6 +45,7 @@
java.lang.ClassLoader, java.lang.ClassLoader,
java.lang.Shutdown, java.lang.Shutdown,
java.lang.ProcessBuilder, java.lang.ProcessBuilder,
sun.misc.Unsafe,
com.opensymphony.xwork2.ActionContext" /> com.opensymphony.xwork2.ActionContext" />
<!-- this must be valid regex, each '.' in package name must be escaped! --> <!-- this must be valid regex, each '.' in package name must be escaped! -->
@@ -56,11 +57,14 @@
value=" value="
ognl., ognl.,
java.io., java.io.,
java.net.,
java.nio.,
javax., javax.,
freemarker.core., freemarker.core.,
freemarker.template., freemarker.template.,
freemarker.ext.jsp., freemarker.ext.jsp.,
freemarker.ext.rhino., freemarker.ext.rhino.,
sun.misc.,
sun.reflect., sun.reflect.,
javassist., javassist.,
org.apache.velocity., org.apache.velocity.,