improve false positive detection in ufuzz (#3977)

This commit is contained in:
Alex Lam S.L
2020-06-09 12:07:02 +01:00
committed by GitHub
parent d764b6cc3b
commit 3b273cecac

View File

@@ -1182,11 +1182,19 @@ function fuzzy_match(original, uglified) {
}
function patch_try_catch(orig, toplevel) {
var code = orig;
var tries = [];
var offset = 0;
var stack = [ {
code: orig,
index: 0,
offset: 0,
tries: [],
} ];
var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^)]+)\)|}\s*finally)\s*(?={)/g;
while (stack.length) {
var code = stack[0].code;
var offset = stack[0].offset;
var tries = stack[0].tries;
var match;
re.lastIndex = stack.shift().index;
while (match = re.exec(code)) {
var index = match.index + match[0].length + 1;
if (/(?:^|[\s{}):;])try\s*$/.test(match[0])) {
@@ -1213,6 +1221,12 @@ function patch_try_catch(orig, toplevel) {
var new_code = code.slice(0, index) + insert + code.slice(index);
var result = sandbox.run_code(new_code, toplevel);
if (typeof result != "object" || typeof result.name != "string" || typeof result.message != "string") {
if (match[1]) stack.push({
code: code,
index: index,
offset: offset,
tries: JSON.parse(JSON.stringify(tries)),
});
offset += insert.length;
code = new_code;
} else if (result.name == "TypeError" && /'in'/.test(result.message)) {
@@ -1223,6 +1237,7 @@ function patch_try_catch(orig, toplevel) {
return orig.slice(0, index) + 'throw new Error("skipping infinite recursion");' + orig.slice(index);
}
}
}
}
var fallback_options = [ JSON.stringify({