diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-06-08 18:47:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 01:47:50 +0800 |
commit | 08c4729eb45e0e7d5ab34a8ffa814b6093822930 (patch) | |
tree | fbde7d83d07519a9541e6c263aa82083e1961304 | |
parent | 5561d3e7f3252837ac3b85401f2403937860da46 (diff) | |
download | tracifyjs-08c4729eb45e0e7d5ab34a8ffa814b6093822930.tar.gz tracifyjs-08c4729eb45e0e7d5ab34a8ffa814b6093822930.zip |
improve false positive detection in `ufuzz` (#3973)
-rw-r--r-- | test/ufuzz/index.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index a9ddb401..c04c896f 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -1188,23 +1188,28 @@ function patch_try_catch(orig, toplevel) { var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^)]+)\)|}\s*finally)\s*(?={)/g; var match; while (match = re.exec(code)) { - if (/}\s*finally\s*$/.test(match[0])) { - tries.shift(); - continue; - } var index = match.index + match[0].length + 1; if (/(?:^|[\s{}):;])try\s*$/.test(match[0])) { tries.unshift({ try: index - offset }); continue; } - while (tries.length && tries[0].catch) tries.shift(); - tries[0].catch = index - offset; - var insert = "throw " + [ - match[1] + ".ufuzz_var || (" + match[1] + '.ufuzz_var = "' + match[1] + '")', - match[1] + ".ufuzz_try || (" + match[1] + ".ufuzz_try = " + tries[0].try + ")", - match[1] + ".ufuzz_catch || (" + match[1] + ".ufuzz_catch = " + tries[0].catch + ")", - match[1], - ].join(", ") + ";"; + var insert; + if (/}\s*finally\s*$/.test(match[0])) { + tries.shift(); + insert = 'if (typeof UFUZZ_ERROR == "object") throw UFUZZ_ERROR;'; + } else { + while (tries.length && tries[0].catch) tries.shift(); + tries[0].catch = index - offset; + insert = [ + "if (!" + match[1] + ".ufuzz_var) {", + match[1] + '.ufuzz_var = "' + match[1] + '";', + match[1] + ".ufuzz_try = " + tries[0].try + ";", + match[1] + ".ufuzz_catch = " + tries[0].catch + ";", + "UFUZZ_ERROR = " + match[1] + ";", + "}", + "throw " + match[1] + ";", + ].join("\n"); + } 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") { |