Skip to content

Commit

Permalink
test and fix for crash parsing regexp /0{0/
Browse files Browse the repository at this point in the history
  • Loading branch information
alagopus committed Jan 16, 2013
1 parent 430456f commit e1f3b3f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/org/mozilla/javascript/regexp/NativeRegExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1121,32 +1121,33 @@ private static void doFlat(CompilerState state, char c)
++state.cp;
min = getDecimalValue(c, state, 0xFFFF,
"msg.overlarge.min");
c = src[state.cp];
if (c == ',') {
c = src[++state.cp];
if (isDigit(c)) {
++state.cp;
max = getDecimalValue(c, state, 0xFFFF,
"msg.overlarge.max");
if (state.cp < src.length) {
c = src[state.cp];
if (c == ',' && ++state.cp < src.length) {
c = src[state.cp];
if (min > max) {
reportError("msg.max.lt.min",
String.valueOf(src[state.cp]));
return false;
if (isDigit(c) && ++state.cp < src.length) {
max = getDecimalValue(c, state, 0xFFFF,
"msg.overlarge.max");
c = src[state.cp];
if (min > max) {
reportError("msg.max.lt.min",
String.valueOf(src[state.cp]));
return false;
}
}
} else {
max = min;
}
/* balance '{' */
if (c == '}') {
state.result = new RENode(REOP_QUANT);
state.result.min = min;
state.result.max = max;
// QUANT, <min>, <max>, <parencount>,
// <parenindex>, <next> ... <ENDCHILD>
state.progLength += 12;
hasQ = true;
}
} else {
max = min;
}
/* balance '{' */
if (c == '}') {
state.result = new RENode(REOP_QUANT);
state.result.min = min;
state.result.max = max;
// QUANT, <min>, <max>, <parencount>,
// <parenindex>, <next> ... <ENDCHILD>
state.progLength += 12;
hasQ = true;
}
}
if (!hasQ) {
Expand Down
29 changes: 29 additions & 0 deletions testsrc/org/mozilla/javascript/tests/NativeRegExpTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.javascript.tests;

import junit.framework.TestCase;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextAction;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.regexp.NativeRegExp;

public class NativeRegExpTest extends TestCase {

public void testOpenBrace() {
final String script = "/0{0/";
final ContextAction action = new ContextAction() {
public Object run(final Context _cx) {
final ScriptableObject scope = _cx.initStandardObjects();
final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
assertEquals(script, Context.toString(result));
return null;
}
};

Utils.runWithAllOptimizationLevels(action);
}
}

0 comments on commit e1f3b3f

Please sign in to comment.