Skip to content

Commit 7399bd0

Browse files
committed
refactor taint
1 parent 634985a commit 7399bd0

12 files changed

Lines changed: 1650 additions & 815 deletions

File tree

rule/apply/apply.mbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ pub fn apply_taint_rules_to_impl(
192192
rules : Array[CompiledRule],
193193
) -> Array[RuleFinding] raise {
194194
let hits : Array[RuleFinding] = []
195+
let untyped_node = @untyped_ast.from_impl(node)
195196
for rule in rules {
196197
match rule.definition {
197198
Taint(taint_rule) =>
198-
apply_taint_rule_to_impl(file, rule, taint_rule, node, hits)
199+
apply_taint_rule_to_impl(file, rule, taint_rule, untyped_node, hits)
199200
_ => ()
200201
}
201202
}
@@ -207,7 +208,7 @@ fn apply_taint_rule_to_impl(
207208
file : String,
208209
rule : CompiledRule,
209210
taint_rule : CompiledTaintRule,
210-
node : @syntax.Impl,
211+
node : @untyped_ast.Node,
211212
hits : Array[RuleFinding],
212213
) -> Unit raise {
213214
let spec = lower_compiled_taint_rule(rule, taint_rule)

rule/taint_lowering/moon.pkg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import {
44
"moonbit-community/moongrep/untyped_ast",
55
"moonbit-community/moongrep/taint",
66
"moonbitlang/lexer/basic",
7-
"moonbitlang/parser/syntax",
87
}
98

109
import {
1110
"moonbit-community/moongrep/rule/compile",
1211
"moonbitlang/parser",
13-
"moonbitlang/parser/syntax",
1412
} for "wbtest"

rule/taint_lowering/taint_lowering.mbt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ fn transfer_compiled_taint_call(
9898
///|
9999
fn taint_pattern_matches(
100100
pattern : CompiledRulePattern,
101-
expr : @syntax.Expr,
101+
node : @untyped_ast.Node,
102102
) -> Bool {
103-
@matching.match_expr_pattern(pattern.compiled, @untyped_ast.from_expr(expr))
104-
is Some(_)
103+
@matching.match_expr_pattern(pattern.compiled, node) is Some(_)
105104
}
106105

107106
///|

rule/taint_lowering/taint_lowering_wbtest.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
using @compile {compile_rules}
33

44
///|
5-
fn parse_single_taint_impl(source : String) -> @syntax.Impl raise {
5+
fn parse_single_taint_impl(source : String) -> @untyped_ast.Node raise {
66
let (impls, reports) = @parser.parse_string(
77
source,
88
name="taint lowering test",
99
)
1010
guard reports is [] else { fail("expected source to parse") }
1111
let nodes = impls.to_array()
1212
guard nodes is [node] else { fail("expected exactly one impl") }
13-
node
13+
@untyped_ast.from_impl(node)
1414
}
1515

1616
///|

taint/api.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/// Analyzes one function or method AST node using one taint specification.
33
///
44
/// Raises `TaintAnalysisError::UnsupportedFunctionLike` when `node` is not a
5-
/// supported function-like parser implementation.
5+
/// supported function-like implementation node.
66
pub fn analyze_function_like(
7-
node : @syntax.Impl,
7+
node : @untyped_ast.Node,
88
spec : TaintSpec,
99
) -> AnalysisResult raise {
1010
analyze_single_function_like(node, spec)
@@ -15,7 +15,7 @@ pub fn analyze_function_like(
1515
///
1616
/// Results are returned in the same order as `rules`.
1717
pub fn analyze_function_like_multi(
18-
node : @syntax.Impl,
18+
node : @untyped_ast.Node,
1919
rules : Array[TaintSpec],
2020
) -> Array[AnalysisResult] raise {
2121
let results : Array[AnalysisResult] = []

0 commit comments

Comments
 (0)