Skip to content

Commit 1575210

Browse files
authored
avoid potential RegExp denial-of-service (#5135)
closes #5133 closes #5134
1 parent f766bab commit 1575210

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11336,7 +11336,7 @@ merge(Compressor.prototype, {
1133611336

1133711337
function decode_template(str) {
1133811338
var malformed = false;
11339-
str = str.replace(/\\(u\{[^}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|[0-9]+|[\s\S])/g, function(match, seq) {
11339+
str = str.replace(/\\(u\{[^{}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|[0-9]+|[\s\S])/g, function(match, seq) {
1134011340
var ch = decode_escape_sequence(seq);
1134111341
if (typeof ch == "string") return ch;
1134211342
malformed = true;

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function push_uniq(array, el) {
143143
}
144144

145145
function string_template(text, props) {
146-
return text.replace(/\{([^}]+)\}/g, function(str, p) {
146+
return text.replace(/\{([^{}]+)\}/g, function(str, p) {
147147
var value = props[p];
148148
return value instanceof AST_Node ? value.print_to_string() : value;
149149
});

test/sandbox.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports.run_code = semver.satisfies(process.version, "0.8") ? function(code, top
2828
if ([
2929
/\basync[ \t]*\([\s\S]*?\)[ \t]*=>/,
3030
/\b(async[ \t]+function|Promise|setImmediate|setInterval|setTimeout)\b/,
31-
/\basync([ \t]+|[ \t]*#|[ \t]*\*[ \t]*)[^\s()[\]{},.&|!~=*%/+-]+(\s*\(|[ \t]*=>)/,
31+
/\basync([ \t]+|[ \t]*#|[ \t]*\*[ \t]*)[^\s()[\]{}#,.&|!~=*%/+-]+(\s*\(|[ \t]*=>)/,
3232
].some(function(pattern) {
3333
return pattern.test(code);
3434
})) {
@@ -51,13 +51,13 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
5151
};
5252
exports.patch_module_statements = function(code) {
5353
var count = 0, imports = [];
54-
code = code.replace(/\bexport(?:\s*\{[^}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
54+
code = code.replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
5555
if (!header) return "";
5656
if (header.length == 1) return "0, " + header;
5757
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
5858
}).replace(/\bimport\.meta\b/g, function() {
5959
return '({ url: "https://example.com/path/index.html" })';
60-
}).replace(/\bimport\b(?:\s*([^('"]+)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
60+
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
6161
if (symbols) {
6262
if (!/^[{*]/.test(symbols)) symbols = "default:" + symbols;
6363
symbols = symbols.replace(/[{}]/g, "").trim().replace(/\s*,\s*/g, ",");

test/ufuzz/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ function patch_try_catch(orig, toplevel) {
23502350
tries: [],
23512351
} ];
23522352
var tail_throw = '\nif (typeof UFUZZ_ERROR == "object") throw UFUZZ_ERROR;\n';
2353-
var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^)[{]+)\)|}\s*finally)\s*(?={)/g;
2353+
var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^()[{]+)\)|}\s*finally)\s*(?={)/g;
23542354
while (stack.length) {
23552355
var code = stack[0].code;
23562356
var offset = stack[0].offset;

0 commit comments

Comments
 (0)