Mercurial > hg > openjdk > jdk8u > nashorn
changeset 2487:637547562431 jdk8u242-b04
Merge
author | andrew |
---|---|
date | Wed, 04 Dec 2019 16:23:50 +0000 |
parents | 61edd0c12ca0 (current diff) 319c1b31d551 (diff) |
children | 191f7b51899b |
files | |
diffstat | 6 files changed, 80 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java Wed Nov 27 05:33:23 2019 +0000 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java Wed Dec 04 16:23:50 2019 +0000 @@ -541,7 +541,6 @@ sprev = s; s++; } - sprev = sbegin; // break; } private void opAnyCharMLStar() { @@ -550,7 +549,6 @@ sprev = s; s++; } - sprev = sbegin; // break; } private void opAnyCharStarPeekNext() {
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/Config.java Wed Nov 27 05:33:23 2019 +0000 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Config.java Wed Dec 04 16:23:50 2019 +0000 @@ -45,6 +45,7 @@ final int NREGION = 10; final int MAX_BACKREF_NUM = 1000; + final int MAX_CAPTURE_GROUP_NUM = 0x8000; final int MAX_REPEAT_NUM = 100000; final int MAX_MULTI_BYTE_RANGES_NUM = 10000;
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/ScanEnvironment.java Wed Nov 27 05:33:23 2019 +0000 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ScanEnvironment.java Wed Dec 04 16:23:50 2019 +0000 @@ -62,6 +62,9 @@ } public int addMemEntry() { + if (numMem >= Config.MAX_CAPTURE_GROUP_NUM) { + throw new InternalException(ErrorMessages.ERR_TOO_MANY_CAPTURE_GROUPS); + } if (numMem++ == 0) { memNodes = new Node[SCANENV_MEMNODES_SIZE]; } else if (numMem >= memNodes.length) {
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/exception/ErrorMessages.java Wed Nov 27 05:33:23 2019 +0000 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/exception/ErrorMessages.java Wed Dec 04 16:23:50 2019 +0000 @@ -31,6 +31,7 @@ final String ERR_PARSER_BUG = "internal parser error (bug)"; final String ERR_UNDEFINED_BYTECODE = "undefined bytecode (bug)"; final String ERR_UNEXPECTED_BYTECODE = "unexpected bytecode (bug)"; + final String ERR_TOO_MANY_CAPTURE_GROUPS = "too many capture groups"; /* syntax error */ final String ERR_END_PATTERN_AT_LEFT_BRACE = "end pattern at left brace";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8204288.js Wed Dec 04 16:23:50 2019 +0000 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8204288: Matching the end of a string followed by an empty greedy regex and a word boundary fails + * + * @test + * @run + */ + + +Assert.assertEquals(new RegExp("c.*\\b").exec("abc")[0], "c"); +Assert.assertEquals(new RegExp("abc.*\\b").exec("abc")[0], "abc"); +Assert.assertEquals(new RegExp("\\b.*abc.*\\b").exec("abc")[0], "abc"); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8204290.js Wed Dec 04 16:23:50 2019 +0000 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8204290: Add check to limit number of capture groups + * + * @test + * @run + */ + +try { + var captureGroups = ""; + for (i=0; i < 0x8001; i++) { captureGroups += "()"; } + new RegExp(captureGroups); + fail("Expected exception"); +} catch (e) { + Assert.assertTrue(e instanceof SyntaxError); + Assert.assertEquals(e.message, "too many capture groups"); +} +