51 lines
1.6 KiB
Diff
51 lines
1.6 KiB
Diff
# UNDF: UNDF-2026-000000021
|
|
diff --git a/src/cargo/ops/tree/mod.rs b/src/cargo/ops/tree/mod.rs
|
|
index 4344daa..4c60bc9 100644
|
|
--- a/src/cargo/ops/tree/mod.rs
|
|
+++ b/src/cargo/ops/tree/mod.rs
|
|
@@ -277,7 +277,8 @@ fn print(
|
|
let mut levels_continue = vec![];
|
|
// The print stack is used to detect dependency cycles when
|
|
// --no-dedupe is used. It contains a Node for each level.
|
|
- let mut print_stack = vec![];
|
|
+ // CWE-407 fix: HashSet for O(1) contains() vs O(n) Vec::contains.
|
|
+ let mut print_stack = HashSet::new();
|
|
|
|
print_node(
|
|
ws,
|
|
@@ -311,7 +312,7 @@ fn print_node<'a>(
|
|
display_depth: DisplayDepth,
|
|
visited_deps: &mut HashSet<NodeId>,
|
|
levels_continue: &mut Vec<(anstyle::Style, bool)>,
|
|
- print_stack: &mut Vec<NodeId>,
|
|
+ print_stack: &mut HashSet<NodeId>,
|
|
) -> CargoResult<()> {
|
|
let new = no_dedupe || visited_deps.insert(node_index);
|
|
|
|
@@ -355,7 +356,7 @@ fn print_node<'a>(
|
|
if !new || in_cycle {
|
|
return Ok(());
|
|
}
|
|
- print_stack.push(node_index);
|
|
+ print_stack.insert(node_index);
|
|
|
|
for kind in &[
|
|
EdgeKind::Dep(DepKind::Normal),
|
|
@@ -379,7 +380,7 @@ fn print_node<'a>(
|
|
kind,
|
|
)?;
|
|
}
|
|
- print_stack.pop();
|
|
+ print_stack.remove(&node_index);
|
|
|
|
Ok(())
|
|
}
|
|
@@ -397,7 +398,7 @@ fn print_dependencies<'a>(
|
|
display_depth: DisplayDepth,
|
|
visited_deps: &mut HashSet<NodeId>,
|
|
levels_continue: &mut Vec<(anstyle::Style, bool)>,
|
|
- print_stack: &mut Vec<NodeId>,
|
|
+ print_stack: &mut HashSet<NodeId>,
|
|
kind: &EdgeKind,
|
|
) -> CargoResult<()> {
|
|
let deps = graph.edges_of_kind(node_index, kind);
|