2026-02-24 23:44:07 -05:00
|
|
|
use crate::labels::{Cap, DataLabel, Kind, LabelRule, ParamConfig};
|
|
|
|
|
use phf::{Map, phf_map};
|
|
|
|
|
|
|
|
|
|
pub static RULES: &[LabelRule] = &[
|
|
|
|
|
// ─────────── Sources ───────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["getenv"],
|
|
|
|
|
label: DataLabel::Source(Cap::all()),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["std::cin", "std::getline", "fgets", "scanf", "gets"],
|
|
|
|
|
label: DataLabel::Source(Cap::all()),
|
|
|
|
|
},
|
|
|
|
|
// ───────── Sanitizers ──────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["sanitize_"],
|
|
|
|
|
label: DataLabel::Sanitizer(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
|
|
|
|
// ─────────── Sinks ─────────────
|
|
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["system", "popen", "execve", "execvp"],
|
|
|
|
|
label: DataLabel::Sink(Cap::SHELL_ESCAPE),
|
|
|
|
|
},
|
|
|
|
|
LabelRule {
|
2026-02-25 04:02:11 -05:00
|
|
|
matchers: &["sprintf", "strcpy", "strcat"],
|
2026-02-24 23:44:07 -05:00
|
|
|
label: DataLabel::Sink(Cap::HTML_ESCAPE),
|
|
|
|
|
},
|
2026-02-25 04:02:11 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["printf", "fprintf"],
|
|
|
|
|
label: DataLabel::Sink(Cap::FMT_STRING),
|
|
|
|
|
},
|
2026-02-25 21:16:36 -05:00
|
|
|
LabelRule {
|
|
|
|
|
matchers: &["fopen", "open"],
|
|
|
|
|
label: DataLabel::Sink(Cap::FILE_IO),
|
|
|
|
|
},
|
2026-02-24 23:44:07 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
pub static KINDS: Map<&'static str, Kind> = phf_map! {
|
|
|
|
|
// control-flow
|
|
|
|
|
"if_statement" => Kind::If,
|
|
|
|
|
"while_statement" => Kind::While,
|
|
|
|
|
"for_statement" => Kind::For,
|
|
|
|
|
"for_range_loop" => Kind::For,
|
|
|
|
|
"do_statement" => Kind::While,
|
2026-02-25 21:16:36 -05:00
|
|
|
"switch_statement" => Kind::Block,
|
|
|
|
|
"case_statement" => Kind::Block,
|
|
|
|
|
"labeled_statement" => Kind::Block,
|
2026-02-24 23:44:07 -05:00
|
|
|
|
|
|
|
|
"return_statement" => Kind::Return,
|
2026-02-25 21:16:36 -05:00
|
|
|
"throw_statement" => Kind::Return,
|
2026-02-24 23:44:07 -05:00
|
|
|
"break_statement" => Kind::Break,
|
|
|
|
|
"continue_statement" => Kind::Continue,
|
|
|
|
|
|
|
|
|
|
// structure
|
|
|
|
|
"translation_unit" => Kind::SourceFile,
|
|
|
|
|
"compound_statement" => Kind::Block,
|
2026-02-25 21:16:36 -05:00
|
|
|
"else_clause" => Kind::Block,
|
2026-02-24 23:44:07 -05:00
|
|
|
"function_definition" => Kind::Function,
|
2026-02-25 21:16:36 -05:00
|
|
|
"try_statement" => Kind::Block,
|
|
|
|
|
"catch_clause" => Kind::Block,
|
|
|
|
|
"lambda_expression" => Kind::Block,
|
2026-02-24 23:44:07 -05:00
|
|
|
|
|
|
|
|
// data-flow
|
|
|
|
|
"call_expression" => Kind::CallFn,
|
|
|
|
|
"assignment_expression" => Kind::Assignment,
|
|
|
|
|
"declaration" => Kind::CallWrapper,
|
|
|
|
|
"expression_statement" => Kind::CallWrapper,
|
|
|
|
|
|
|
|
|
|
// trivia
|
|
|
|
|
"comment" => Kind::Trivia,
|
|
|
|
|
";" => Kind::Trivia, "," => Kind::Trivia,
|
|
|
|
|
"(" => Kind::Trivia, ")" => Kind::Trivia,
|
|
|
|
|
"{" => Kind::Trivia, "}" => Kind::Trivia,
|
|
|
|
|
"\n" => Kind::Trivia,
|
|
|
|
|
"preproc_include" => Kind::Trivia,
|
|
|
|
|
"preproc_def" => Kind::Trivia,
|
|
|
|
|
"using_declaration" => Kind::Trivia,
|
2026-02-25 21:16:36 -05:00
|
|
|
"namespace_definition" => Kind::Block,
|
2026-02-24 23:44:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub static PARAM_CONFIG: ParamConfig = ParamConfig {
|
|
|
|
|
params_field: "parameters",
|
|
|
|
|
param_node_kinds: &["parameter_declaration"],
|
|
|
|
|
self_param_kinds: &[],
|
|
|
|
|
ident_fields: &["declarator", "name"],
|
|
|
|
|
};
|