Skip to content

Commit

Permalink
CVE-2021-28170 Fix expression delimiter escaping (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: rmartinc rmartinc@redhat.com
  • Loading branch information
TomasHofman committed Aug 16, 2021
1 parent ab8e8c0 commit fe0c60b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions impl/src/main/java/com/sun/el/parser/ELParser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ TOKEN_MGR_DECLS:
< LITERAL_EXPRESSION:
((~["\\", "$", "#"])
| ("\\" ("\\" | "$" | "#"))
| ("$" ~["{", "$", "#"])
| ("#" ~["{", "$", "#"])
| ("$" ~["{", "$", "#", "\\"])
| ("#" ~["{", "$", "#", "\\"])
)+
| "$"
| "#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

/* Generated By:JJTree&JavaCC: Do not edit this line. ELParserTokenManager.java */
package com.sun.el.parser;
import java.io.StringReader;
import jakarta.el.ELException;

/** Token Manager. */
public class ELParserTokenManager implements ELParserConstants
Expand Down Expand Up @@ -201,7 +199,7 @@ else if (curChar == 92)
jjCheckNAddStates(0, 3);
break;
case 4:
if ((0xf7ffffffffffffffL & l) == 0L)
if ((0xf7ffffffefffffffL & l) == 0L)
break;
if (kind > 1)
kind = 1;
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/org/glassfish/el/test/EscapingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.glassfish.el.test;

import jakarta.el.ELManager;
import jakarta.el.ELProcessor;
import jakarta.el.ValueExpression;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class EscapingTest {

static ELProcessor elp;
static ELManager elm;

public EscapingTest() {
}

@BeforeClass
public static void setUpClass() throws Exception {
elp = new ELProcessor();
elm = elp.getELManager();
}

@Test
public void testEscape01() {
assertEquals("$2", evaluateExpression("$${1+1}"));
assertEquals("$${1+1}", evaluateExpression("$\\${1+1}"));
}

@Test
public void testEscape02() {
assertEquals("$2", evaluateExpression("$#{1+1}"));
assertEquals("$#{1+1}", evaluateExpression("$\\#{1+1}"));
}

@Test
public void testEscape03() {
assertEquals("#2", evaluateExpression("##{1+1}"));
assertEquals("##{1+1}", evaluateExpression("#\\#{1+1}"));
}

@Test
public void testEscape04() {
assertEquals("#2", evaluateExpression("#${1+1}"));
assertEquals("#${1+1}", evaluateExpression("#\\${1+1}"));
}

private String evaluateExpression(String expr) {
ValueExpression v = ELManager.getExpressionFactory().createValueExpression(
elm.getELContext(), expr, String.class);
return (String) v.getValue(elm.getELContext());
}
}

0 comments on commit fe0c60b

Please sign in to comment.