circle-ir 4.17.0 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/advisories.d.ts +186 -0
- package/dist/analysis/advisories.d.ts.map +1 -0
- package/dist/analysis/advisories.js +391 -0
- package/dist/analysis/advisories.js.map +1 -0
- package/dist/analysis/comment-lines.d.ts +14 -0
- package/dist/analysis/comment-lines.d.ts.map +1 -0
- package/dist/analysis/comment-lines.js +34 -0
- package/dist/analysis/comment-lines.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +81 -27
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +2 -2
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +205 -29
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +4 -0
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +99 -0
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/entry-point-detection.d.ts.map +1 -1
- package/dist/analysis/entry-point-detection.js +72 -0
- package/dist/analysis/entry-point-detection.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts +6 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +124 -10
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/js-helper-return.d.ts +12 -0
- package/dist/analysis/js-helper-return.d.ts.map +1 -0
- package/dist/analysis/js-helper-return.js +64 -0
- package/dist/analysis/js-helper-return.js.map +1 -0
- package/dist/analysis/maven-declared.d.ts +72 -0
- package/dist/analysis/maven-declared.d.ts.map +1 -0
- package/dist/analysis/maven-declared.js +216 -0
- package/dist/analysis/maven-declared.js.map +1 -0
- package/dist/analysis/maven-version.d.ts +28 -0
- package/dist/analysis/maven-version.d.ts.map +1 -0
- package/dist/analysis/maven-version.js +172 -0
- package/dist/analysis/maven-version.js.map +1 -0
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +29 -1
- package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +81 -1
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts +7 -0
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +44 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.d.ts +2 -0
- package/dist/analysis/passes/insecure-cookie-pass.d.ts.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.js +25 -3
- package/dist/analysis/passes/insecure-cookie-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +11 -14
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +564 -0
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +18 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +1097 -15
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +66 -3
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +5 -1
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts +44 -2
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +728 -13
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +133 -10
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts +18 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.js +161 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.js.map +1 -1
- package/dist/analysis/passes/weak-random-pass.d.ts +6 -0
- package/dist/analysis/passes/weak-random-pass.d.ts.map +1 -1
- package/dist/analysis/passes/weak-random-pass.js +29 -0
- package/dist/analysis/passes/weak-random-pass.js.map +1 -1
- package/dist/analysis/promote-cross-file-flows.d.ts +17 -0
- package/dist/analysis/promote-cross-file-flows.d.ts.map +1 -0
- package/dist/analysis/promote-cross-file-flows.js +32 -0
- package/dist/analysis/promote-cross-file-flows.js.map +1 -0
- package/dist/analysis/sbom.d.ts +100 -0
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +514 -3
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/semver-version.d.ts +30 -0
- package/dist/analysis/semver-version.d.ts.map +1 -0
- package/dist/analysis/semver-version.js +76 -0
- package/dist/analysis/semver-version.js.map +1 -0
- package/dist/analysis/taint-matcher.d.ts +5 -0
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +293 -6
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +57 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +69 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3156 -323
- package/dist/core/circle-ir-core.cjs +951 -409
- package/dist/core/circle-ir-core.js +951 -409
- package/dist/core/extractors/dfg.js +244 -2
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +39 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -0
- package/dist/core/extractors/ts-declaration-detail.js +266 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -0
- package/dist/graph/analysis-pass.d.ts +4 -1
- package/dist/graph/analysis-pass.d.ts.map +1 -1
- package/dist/graph/analysis-pass.js +4 -1
- package/dist/graph/analysis-pass.js.map +1 -1
- package/dist/graph-facts/dead-code.d.ts +62 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -0
- package/dist/graph-facts/dead-code.js +90 -0
- package/dist/graph-facts/dead-code.js.map +1 -0
- package/dist/graph-facts/dependency-calls.d.ts +86 -0
- package/dist/graph-facts/dependency-calls.d.ts.map +1 -0
- package/dist/graph-facts/dependency-calls.js +93 -0
- package/dist/graph-facts/dependency-calls.js.map +1 -0
- package/dist/graph-facts/index.d.ts +10 -0
- package/dist/graph-facts/index.d.ts.map +1 -0
- package/dist/graph-facts/index.js +10 -0
- package/dist/graph-facts/index.js.map +1 -0
- package/dist/graph-facts/maven-packages.d.ts +42 -0
- package/dist/graph-facts/maven-packages.d.ts.map +1 -0
- package/dist/graph-facts/maven-packages.js +133 -0
- package/dist/graph-facts/maven-packages.js.map +1 -0
- package/dist/graph-facts/reach.d.ts +203 -0
- package/dist/graph-facts/reach.d.ts.map +1 -0
- package/dist/graph-facts/reach.js +219 -0
- package/dist/graph-facts/reach.js.map +1 -0
- package/dist/graph-facts/removal-reach.d.ts +73 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -0
- package/dist/graph-facts/removal-reach.js +64 -0
- package/dist/graph-facts/removal-reach.js.map +1 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/navigation/go-graph.d.ts +68 -0
- package/dist/navigation/go-graph.d.ts.map +1 -0
- package/dist/navigation/go-graph.js +753 -0
- package/dist/navigation/go-graph.js.map +1 -0
- package/dist/navigation/index.d.ts +7 -1
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +6 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-entry-tables.d.ts +43 -0
- package/dist/navigation/java-entry-tables.d.ts.map +1 -0
- package/dist/navigation/java-entry-tables.js +56 -0
- package/dist/navigation/java-entry-tables.js.map +1 -0
- package/dist/navigation/java-graph.d.ts +64 -0
- package/dist/navigation/java-graph.d.ts.map +1 -0
- package/dist/navigation/java-graph.js +466 -0
- package/dist/navigation/java-graph.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +51 -1
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +72 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/python-graph.d.ts +73 -0
- package/dist/navigation/python-graph.d.ts.map +1 -0
- package/dist/navigation/python-graph.js +867 -0
- package/dist/navigation/python-graph.js.map +1 -0
- package/dist/navigation/ts-call-edges.d.ts +193 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -0
- package/dist/navigation/ts-call-edges.js +2089 -0
- package/dist/navigation/ts-call-edges.js.map +1 -0
- package/dist/navigation/ts-entry-tables.d.ts +88 -0
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -0
- package/dist/navigation/ts-entry-tables.js +50 -0
- package/dist/navigation/ts-entry-tables.js.map +1 -0
- package/dist/path-set/branches.d.ts +52 -0
- package/dist/path-set/branches.d.ts.map +1 -0
- package/dist/path-set/branches.js +124 -0
- package/dist/path-set/branches.js.map +1 -0
- package/dist/path-set/finding-diff.d.ts +63 -0
- package/dist/path-set/finding-diff.d.ts.map +1 -0
- package/dist/path-set/finding-diff.js +150 -0
- package/dist/path-set/finding-diff.js.map +1 -0
- package/dist/path-set/index.d.ts +18 -0
- package/dist/path-set/index.d.ts.map +1 -0
- package/dist/path-set/index.js +12 -0
- package/dist/path-set/index.js.map +1 -0
- package/dist/path-set/line-diff.d.ts +19 -0
- package/dist/path-set/line-diff.d.ts.map +1 -0
- package/dist/path-set/line-diff.js +98 -0
- package/dist/path-set/line-diff.js.map +1 -0
- package/dist/path-set/path-set.d.ts +88 -0
- package/dist/path-set/path-set.d.ts.map +1 -0
- package/dist/path-set/path-set.js +716 -0
- package/dist/path-set/path-set.js.map +1 -0
- package/dist/path-set/templates.d.ts +42 -0
- package/dist/path-set/templates.d.ts.map +1 -0
- package/dist/path-set/templates.js +119 -0
- package/dist/path-set/templates.js.map +1 -0
- package/dist/path-set/types.d.ts +195 -0
- package/dist/path-set/types.d.ts.map +1 -0
- package/dist/path-set/types.js +8 -0
- package/dist/path-set/types.js.map +1 -0
- package/dist/remedy-class/index.d.ts +12 -0
- package/dist/remedy-class/index.d.ts.map +1 -0
- package/dist/remedy-class/index.js +9 -0
- package/dist/remedy-class/index.js.map +1 -0
- package/dist/remedy-class/match.d.ts +165 -0
- package/dist/remedy-class/match.d.ts.map +1 -0
- package/dist/remedy-class/match.js +705 -0
- package/dist/remedy-class/match.js.map +1 -0
- package/dist/remedy-class/output-context.d.ts +25 -0
- package/dist/remedy-class/output-context.d.ts.map +1 -0
- package/dist/remedy-class/output-context.js +150 -0
- package/dist/remedy-class/output-context.js.map +1 -0
- package/dist/remedy-class/sha256.d.ts +18 -0
- package/dist/remedy-class/sha256.d.ts.map +1 -0
- package/dist/remedy-class/sha256.js +89 -0
- package/dist/remedy-class/sha256.js.map +1 -0
- package/dist/remedy-class/table.d.ts +130 -0
- package/dist/remedy-class/table.d.ts.map +1 -0
- package/dist/remedy-class/table.js +457 -0
- package/dist/remedy-class/table.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +11 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +82 -5
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/builder.d.ts +20 -0
- package/dist/stable-ids/builder.d.ts.map +1 -0
- package/dist/stable-ids/builder.js +65 -0
- package/dist/stable-ids/builder.js.map +1 -0
- package/dist/stable-ids/diff.d.ts +18 -0
- package/dist/stable-ids/diff.d.ts.map +1 -0
- package/dist/stable-ids/diff.js +37 -0
- package/dist/stable-ids/diff.js.map +1 -0
- package/dist/stable-ids/go.d.ts +28 -0
- package/dist/stable-ids/go.d.ts.map +1 -0
- package/dist/stable-ids/go.js +160 -0
- package/dist/stable-ids/go.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +22 -0
- package/dist/stable-ids/hash.d.ts.map +1 -0
- package/dist/stable-ids/hash.js +167 -0
- package/dist/stable-ids/hash.js.map +1 -0
- package/dist/stable-ids/index.d.ts +30 -0
- package/dist/stable-ids/index.d.ts.map +1 -0
- package/dist/stable-ids/index.js +59 -0
- package/dist/stable-ids/index.js.map +1 -0
- package/dist/stable-ids/java.d.ts +28 -0
- package/dist/stable-ids/java.d.ts.map +1 -0
- package/dist/stable-ids/java.js +224 -0
- package/dist/stable-ids/java.js.map +1 -0
- package/dist/stable-ids/moves.d.ts +87 -0
- package/dist/stable-ids/moves.d.ts.map +1 -0
- package/dist/stable-ids/moves.js +222 -0
- package/dist/stable-ids/moves.js.map +1 -0
- package/dist/stable-ids/nodes.d.ts +32 -0
- package/dist/stable-ids/nodes.d.ts.map +1 -0
- package/dist/stable-ids/nodes.js +92 -0
- package/dist/stable-ids/nodes.js.map +1 -0
- package/dist/stable-ids/normalize.d.ts +35 -0
- package/dist/stable-ids/normalize.d.ts.map +1 -0
- package/dist/stable-ids/normalize.js +174 -0
- package/dist/stable-ids/normalize.js.map +1 -0
- package/dist/stable-ids/parse-errors.d.ts +24 -0
- package/dist/stable-ids/parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/parse-errors.js +46 -0
- package/dist/stable-ids/parse-errors.js.map +1 -0
- package/dist/stable-ids/python.d.ts +27 -0
- package/dist/stable-ids/python.d.ts.map +1 -0
- package/dist/stable-ids/python.js +212 -0
- package/dist/stable-ids/python.js.map +1 -0
- package/dist/stable-ids/ts-parse-errors.d.ts +27 -0
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/ts-parse-errors.js +75 -0
- package/dist/stable-ids/ts-parse-errors.js.map +1 -0
- package/dist/stable-ids/types.d.ts +106 -0
- package/dist/stable-ids/types.d.ts.map +1 -0
- package/dist/stable-ids/types.js +16 -0
- package/dist/stable-ids/types.js.map +1 -0
- package/dist/stable-ids/typescript.d.ts +30 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -0
- package/dist/stable-ids/typescript.js +362 -0
- package/dist/stable-ids/typescript.js.map +1 -0
- package/dist/types/config.d.ts +9 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -664,6 +664,133 @@ function processStatement(stmt, startDefId, startUseId, scopeStack, isJavaScript
|
|
|
664
664
|
carryBranchDefsOut(popped, scopeStack, alwaysRuns);
|
|
665
665
|
break;
|
|
666
666
|
}
|
|
667
|
+
case 'try_statement':
|
|
668
|
+
case 'try_with_resources_statement': {
|
|
669
|
+
// Before this case a `try` recorded uses only, so no local declared in a
|
|
670
|
+
// try body, catch or finally — nor a try-with-resources resource — had a
|
|
671
|
+
// def, and nothing used inside or after it had a reaching def.
|
|
672
|
+
if (isJavaScript) {
|
|
673
|
+
// JavaScript / TypeScript: `try { } catch (e | { pattern }) { } finally { }`
|
|
674
|
+
const tryBody = stmt.childForFieldName('body');
|
|
675
|
+
if (tryBody) {
|
|
676
|
+
const r = processStatement(tryBody, defId, useId, scopeStack, isJavaScript);
|
|
677
|
+
defs.push(...r.defs);
|
|
678
|
+
uses.push(...r.uses);
|
|
679
|
+
defId = r.nextDefId;
|
|
680
|
+
useId = r.nextUseId;
|
|
681
|
+
}
|
|
682
|
+
const handler = stmt.childForFieldName('handler');
|
|
683
|
+
if (handler) {
|
|
684
|
+
scopeStack.push(new Map());
|
|
685
|
+
const param = handler.childForFieldName('parameter');
|
|
686
|
+
if (param) {
|
|
687
|
+
const paramDefs = param.type === 'identifier'
|
|
688
|
+
? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: 'local' }]
|
|
689
|
+
: extractDestructuringDefs(param, defId);
|
|
690
|
+
for (const def of paramDefs) {
|
|
691
|
+
defs.push(def);
|
|
692
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
693
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
694
|
+
defId++;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const handlerBody = handler.childForFieldName('body');
|
|
698
|
+
if (handlerBody) {
|
|
699
|
+
const r = processStatement(handlerBody, defId, useId, scopeStack, isJavaScript);
|
|
700
|
+
defs.push(...r.defs);
|
|
701
|
+
uses.push(...r.uses);
|
|
702
|
+
defId = r.nextDefId;
|
|
703
|
+
useId = r.nextUseId;
|
|
704
|
+
}
|
|
705
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
706
|
+
}
|
|
707
|
+
const finalizer = stmt.childForFieldName('finalizer');
|
|
708
|
+
const finallyBody = finalizer?.childForFieldName('body');
|
|
709
|
+
if (finallyBody) {
|
|
710
|
+
const r = processStatement(finallyBody, defId, useId, scopeStack, isJavaScript);
|
|
711
|
+
defs.push(...r.defs);
|
|
712
|
+
uses.push(...r.uses);
|
|
713
|
+
defId = r.nextDefId;
|
|
714
|
+
useId = r.nextUseId;
|
|
715
|
+
}
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
// Resources are scoped to the statement: visible in the body, gone after it.
|
|
719
|
+
scopeStack.push(new Map());
|
|
720
|
+
const resources = stmt.childForFieldName('resources');
|
|
721
|
+
for (const res of resources?.namedChildren ?? []) {
|
|
722
|
+
if (!res || res.type !== 'resource')
|
|
723
|
+
continue;
|
|
724
|
+
const nameNode = res.childForFieldName('name');
|
|
725
|
+
const value = res.childForFieldName('value');
|
|
726
|
+
if (value) {
|
|
727
|
+
const valueUses = extractUses(value, useId, scopeStack, isJavaScript);
|
|
728
|
+
uses.push(...valueUses.uses);
|
|
729
|
+
useId = valueUses.nextId;
|
|
730
|
+
}
|
|
731
|
+
if (nameNode && nameNode.type === 'identifier') {
|
|
732
|
+
const def = { id: defId++, variable: getNodeText(nameNode), line: nameNode.startPosition.row + 1, column: nameNode.startPosition.column, kind: 'local' };
|
|
733
|
+
defs.push(def);
|
|
734
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
735
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
736
|
+
}
|
|
737
|
+
else if (!value) {
|
|
738
|
+
// `try (existing)`: an effectively final variable or field, a use
|
|
739
|
+
const resUses = extractUses(res, useId, scopeStack, isJavaScript);
|
|
740
|
+
uses.push(...resUses.uses);
|
|
741
|
+
useId = resUses.nextId;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
for (const part of stmt.namedChildren) {
|
|
745
|
+
if (!part)
|
|
746
|
+
continue;
|
|
747
|
+
if (part.type === 'block') {
|
|
748
|
+
// the try body: a block whose parent is the try, so its defs are carried
|
|
749
|
+
// out as alternates (it may stop part way)
|
|
750
|
+
const r = processStatement(part, defId, useId, scopeStack, isJavaScript);
|
|
751
|
+
defs.push(...r.defs);
|
|
752
|
+
uses.push(...r.uses);
|
|
753
|
+
defId = r.nextDefId;
|
|
754
|
+
useId = r.nextUseId;
|
|
755
|
+
}
|
|
756
|
+
else if (part.type === 'catch_clause') {
|
|
757
|
+
scopeStack.push(new Map());
|
|
758
|
+
for (const param of part.namedChildren) {
|
|
759
|
+
if (!param || param.type !== 'catch_formal_parameter')
|
|
760
|
+
continue;
|
|
761
|
+
const pname = param.childForFieldName('name');
|
|
762
|
+
if (pname) {
|
|
763
|
+
const def = { id: defId++, variable: getNodeText(pname), line: pname.startPosition.row + 1, column: pname.startPosition.column, kind: 'local' };
|
|
764
|
+
defs.push(def);
|
|
765
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
766
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
const body = part.childForFieldName('body');
|
|
770
|
+
if (body) {
|
|
771
|
+
const r = processStatement(body, defId, useId, scopeStack, isJavaScript);
|
|
772
|
+
defs.push(...r.defs);
|
|
773
|
+
uses.push(...r.uses);
|
|
774
|
+
defId = r.nextDefId;
|
|
775
|
+
useId = r.nextUseId;
|
|
776
|
+
}
|
|
777
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
778
|
+
}
|
|
779
|
+
else if (part.type === 'finally_clause') {
|
|
780
|
+
for (const b of part.namedChildren) {
|
|
781
|
+
if (!b || b.type !== 'block')
|
|
782
|
+
continue;
|
|
783
|
+
const r = processStatement(b, defId, useId, scopeStack, isJavaScript);
|
|
784
|
+
defs.push(...r.defs);
|
|
785
|
+
uses.push(...r.uses);
|
|
786
|
+
defId = r.nextDefId;
|
|
787
|
+
useId = r.nextUseId;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
667
794
|
case 'else_clause': {
|
|
668
795
|
// JavaScript: `else { … }` / `else if (…) { … }` hold their arm one level
|
|
669
796
|
// down; without this the arm fell to `default` and recorded no defs, so an
|
|
@@ -1552,6 +1679,53 @@ function buildBashDFG(tree) {
|
|
|
1552
1679
|
defs.push(def);
|
|
1553
1680
|
currentScope(scopeStack).set(p, def.id);
|
|
1554
1681
|
}
|
|
1682
|
+
// Positional parameters inside a function body are that function's own
|
|
1683
|
+
// arguments, not the script's (cognium-dev dogfood: a script-level `$2`
|
|
1684
|
+
// source reached every `"$2"` inside every helper function). Each
|
|
1685
|
+
// function gets its own synthetic positional defs at its header line;
|
|
1686
|
+
// a call `fname a b` chains the caller's defs used in argument k into the
|
|
1687
|
+
// function's def for `$k` (`"$@"` / `"$*"` into all of them).
|
|
1688
|
+
const bashFnDefs = new Map();
|
|
1689
|
+
const bashFnByNodeId = new Map();
|
|
1690
|
+
for (const fn of findNodes(tree.rootNode, 'function_definition')) {
|
|
1691
|
+
const nameNode = fn.childForFieldName('name');
|
|
1692
|
+
if (!nameNode)
|
|
1693
|
+
continue;
|
|
1694
|
+
const fnName = getNodeText(nameNode);
|
|
1695
|
+
if (!fnName || bashFnDefs.has(fnName))
|
|
1696
|
+
continue;
|
|
1697
|
+
const m = new Map();
|
|
1698
|
+
for (const p of positionalParams) {
|
|
1699
|
+
const def = {
|
|
1700
|
+
id: defIdCounter++,
|
|
1701
|
+
variable: p,
|
|
1702
|
+
line: fn.startPosition.row + 1,
|
|
1703
|
+
kind: 'param',
|
|
1704
|
+
expression: `bash-fn:${fnName}`,
|
|
1705
|
+
};
|
|
1706
|
+
defs.push(def);
|
|
1707
|
+
m.set(p, def.id);
|
|
1708
|
+
}
|
|
1709
|
+
bashFnDefs.set(fnName, m);
|
|
1710
|
+
bashFnByNodeId.set(fn.id, fnName);
|
|
1711
|
+
}
|
|
1712
|
+
const enclosingBashFn = (node) => {
|
|
1713
|
+
let cur = node.parent;
|
|
1714
|
+
while (cur) {
|
|
1715
|
+
if (cur.type === 'function_definition')
|
|
1716
|
+
return bashFnByNodeId.get(cur.id) ?? null;
|
|
1717
|
+
cur = cur.parent;
|
|
1718
|
+
}
|
|
1719
|
+
return null;
|
|
1720
|
+
};
|
|
1721
|
+
const positionalDef = (varName, node, fallback) => {
|
|
1722
|
+
if (!positionalParams.includes(varName))
|
|
1723
|
+
return fallback;
|
|
1724
|
+
const fnName = enclosingBashFn(node);
|
|
1725
|
+
if (!fnName)
|
|
1726
|
+
return fallback;
|
|
1727
|
+
return bashFnDefs.get(fnName)?.get(varName) ?? fallback;
|
|
1728
|
+
};
|
|
1555
1729
|
walkTree(tree.rootNode, (node) => {
|
|
1556
1730
|
if (node.type === 'variable_assignment') {
|
|
1557
1731
|
// VAR=value — Tree-sitter Bash: variable_assignment has `name` and `value` fields
|
|
@@ -1617,7 +1791,7 @@ function buildBashDFG(tree) {
|
|
|
1617
1791
|
if (varNameNode) {
|
|
1618
1792
|
const varName = getNodeText(varNameNode);
|
|
1619
1793
|
if (varName && !varName.startsWith('?') && !varName.startsWith('#')) {
|
|
1620
|
-
let reachingDef = findReachingDef(varName, scopeStack);
|
|
1794
|
+
let reachingDef = positionalDef(varName, node, findReachingDef(varName, scopeStack));
|
|
1621
1795
|
// If the variable has no reaching def (i.e. it's an env var or an
|
|
1622
1796
|
// unbound identifier), synthesize a `param`-kind def at line 0 so that
|
|
1623
1797
|
// env-sourced taint can be seeded and propagated through the DFG.
|
|
@@ -1648,7 +1822,7 @@ function buildBashDFG(tree) {
|
|
|
1648
1822
|
const varNameNode = node.namedChildCount > 0 ? node.namedChild(0) : null;
|
|
1649
1823
|
if (varNameNode && varNameNode.type === 'variable_name') {
|
|
1650
1824
|
const varName = getNodeText(varNameNode);
|
|
1651
|
-
let reachingDef = findReachingDef(varName, scopeStack);
|
|
1825
|
+
let reachingDef = positionalDef(varName, node, findReachingDef(varName, scopeStack));
|
|
1652
1826
|
if (reachingDef === null && !positionalParams.includes(varName)) {
|
|
1653
1827
|
const def = {
|
|
1654
1828
|
id: defIdCounter++,
|
|
@@ -1670,8 +1844,76 @@ function buildBashDFG(tree) {
|
|
|
1670
1844
|
}
|
|
1671
1845
|
});
|
|
1672
1846
|
const chains = computeChains(defs, uses);
|
|
1847
|
+
chains.push(...bashCallArgChains(tree, bashFnDefs, uses, positionalParams));
|
|
1673
1848
|
return { defs, uses, chains };
|
|
1674
1849
|
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Bash: chain the caller's defs used in each argument of a call to a function
|
|
1852
|
+
* defined in the same file into that function's positional defs. A body that
|
|
1853
|
+
* uses `shift` or `set --` renumbers its parameters, so there every argument
|
|
1854
|
+
* reaches every positional def of the function.
|
|
1855
|
+
*/
|
|
1856
|
+
function bashCallArgChains(tree, bashFnDefs, uses, positionalParams) {
|
|
1857
|
+
const chains = [];
|
|
1858
|
+
if (bashFnDefs.size === 0)
|
|
1859
|
+
return chains;
|
|
1860
|
+
const renumbers = new Set();
|
|
1861
|
+
for (const fn of findNodes(tree.rootNode, 'function_definition')) {
|
|
1862
|
+
const nameNode = fn.childForFieldName('name');
|
|
1863
|
+
if (!nameNode)
|
|
1864
|
+
continue;
|
|
1865
|
+
if (/\bshift\b|\bset\s+--/.test(getNodeText(fn)))
|
|
1866
|
+
renumbers.add(getNodeText(nameNode));
|
|
1867
|
+
}
|
|
1868
|
+
const usesByLine = new Map();
|
|
1869
|
+
for (const u of uses) {
|
|
1870
|
+
const l = usesByLine.get(u.line) ?? [];
|
|
1871
|
+
l.push(u);
|
|
1872
|
+
usesByLine.set(u.line, l);
|
|
1873
|
+
}
|
|
1874
|
+
for (const cmd of findNodes(tree.rootNode, 'command')) {
|
|
1875
|
+
const nameNode = cmd.childForFieldName('name');
|
|
1876
|
+
if (!nameNode)
|
|
1877
|
+
continue;
|
|
1878
|
+
const fnDefs = bashFnDefs.get(getNodeText(nameNode));
|
|
1879
|
+
if (!fnDefs)
|
|
1880
|
+
continue;
|
|
1881
|
+
const fnName = getNodeText(nameNode);
|
|
1882
|
+
let position = 0;
|
|
1883
|
+
for (let i = 0; i < cmd.childCount; i++) {
|
|
1884
|
+
const arg = cmd.child(i);
|
|
1885
|
+
if (!arg || arg.id === nameNode.id)
|
|
1886
|
+
continue;
|
|
1887
|
+
if (arg.type.includes('redirect') || arg.type === 'heredoc_body' || arg.type === 'file_descriptor')
|
|
1888
|
+
continue;
|
|
1889
|
+
const text = getNodeText(arg);
|
|
1890
|
+
if (!text.trim())
|
|
1891
|
+
continue;
|
|
1892
|
+
position++;
|
|
1893
|
+
const names = new Set();
|
|
1894
|
+
const re = /\$\{?([A-Za-z_][A-Za-z0-9_]*|[0-9@*])/g;
|
|
1895
|
+
let m;
|
|
1896
|
+
while ((m = re.exec(text)) !== null)
|
|
1897
|
+
names.add(m[1]);
|
|
1898
|
+
if (names.size === 0)
|
|
1899
|
+
continue;
|
|
1900
|
+
const spreads = /\$\{?[@*]/.test(text);
|
|
1901
|
+
const targets = spreads || renumbers.has(fnName)
|
|
1902
|
+
? positionalParams.map(p => fnDefs.get(p)).filter((d) => d !== undefined)
|
|
1903
|
+
: [fnDefs.get(String(position))].filter((d) => d !== undefined);
|
|
1904
|
+
const lineUses = usesByLine.get(arg.startPosition.row + 1) ?? [];
|
|
1905
|
+
for (const name of names) {
|
|
1906
|
+
for (const u of lineUses) {
|
|
1907
|
+
if (u.variable !== name || u.def_id === null)
|
|
1908
|
+
continue;
|
|
1909
|
+
for (const t of targets)
|
|
1910
|
+
chains.push({ from_def: u.def_id, to_def: t, via: name });
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
return chains;
|
|
1916
|
+
}
|
|
1675
1917
|
/**
|
|
1676
1918
|
* Build DFG for Rust code.
|
|
1677
1919
|
*/
|