Skip to content

Commit

Permalink
Add get_source_functions method
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 18, 2024
1 parent 63d619a commit 65fcbc8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/code_info/data_flow/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use super::{
node::{DataFlowNode, DataFlowNodeId, DataFlowNodeKind},
path::{DataFlowPath, PathKind},
};
use crate::{code_location::FilePath, taint::SinkType};
use crate::{
code_location::FilePath, function_context::FunctionLikeIdentifier, t_union::TUnion,
taint::SinkType,
};
use oxidized::ast_defs::Pos;
use rustc_hash::{FxHashMap, FxHashSet};

Expand Down Expand Up @@ -258,4 +261,30 @@ impl DataFlowGraph {
}
}
}

pub fn get_source_functions(&self, expr_type: &TUnion) -> Vec<FunctionLikeIdentifier> {
let mut origin_node_ids = vec![];

for parent_node in &expr_type.parent_nodes {
origin_node_ids.extend(self.get_origin_node_ids(&parent_node.id, vec![], false));
}

let mut source_functions = vec![];

for origin_node_id in origin_node_ids {
match &origin_node_id {
DataFlowNodeId::CallTo(functionlike_id)
| DataFlowNodeId::SpecializedCallTo(functionlike_id, ..) => {
let origin_node = self.get_node(&origin_node_id).unwrap();

if let DataFlowNodeKind::Vertex { .. } = origin_node.kind {
source_functions.push(*functionlike_id);
}
}
_ => {}
}
}

source_functions
}
}

0 comments on commit 65fcbc8

Please sign in to comment.