fix corner cases in infinite recursion detection (#3924)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 25 May 2020 14:54:57 +0000 (15:54 +0100)
committerGitHub <noreply@github.com>
Mon, 25 May 2020 14:54:57 +0000 (22:54 +0800)
test/ufuzz/index.js

index ed687de..df946c9 100644 (file)
@@ -1177,19 +1177,19 @@ function skip_infinite_recursion(orig, toplevel) {
     var code = orig;
     var tries = [];
     var offset = 0;
-    var re = /(?:(?:^|[\s{};])try|}\s*catch\s*\(([^)]+)\)|}\s*finally)\s*(?={)/g;
+    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;
         }
-        if (tries.length && tries[0].catch) tries.shift();
         var index = match.index + match[0].length + 1;
-        if (/(?:^|[\s{};])try\s*$/.test(match[0])) {
+        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;
         var insert = "throw " + match[1] + ".ufuzz_skip || (" + match[1] + ".ufuzz_skip = " + tries[0].try + "), " + match[1] + ";";
         var new_code = code.slice(0, index) + insert + code.slice(index);