Skip to content

Commit

Permalink
Fixed unprotected-mapping-operation detector to prevent a stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosiggio committed Aug 2, 2023
1 parent 97fb366 commit bc618fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions detectors/unprotected-mapping-operation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate rustc_middle;
extern crate rustc_span;

use clippy_utils::diagnostics::span_lint;
use std::collections::HashSet;
use rustc_hir::QPath;
use rustc_hir::{
intravisit::{walk_expr, Visitor},
Expand Down Expand Up @@ -147,6 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
&caller_and_map_ops,
false,
&mut vec![],
&mut HashSet::<BasicBlock>::default()
);
for place in unchecked_places {
span_lint(
Expand All @@ -164,8 +166,14 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops: &CallersAndMapOps<'tcx>,
after_comparison: bool,
tainted_places: &mut Vec<Place<'tcx>>,
visited_bbs: &mut HashSet<BasicBlock>,
) -> Vec<(Place<'tcx>, Span)> {
let mut ret_vec = Vec::<(Place, Span)>::new();
if visited_bbs.contains(&bb) {
return ret_vec;
} else {
visited_bbs.insert(bb);
}
if bbs[bb].terminator.is_none() {
return ret_vec;
}
Expand Down Expand Up @@ -221,6 +229,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
comparison_with_caller,
tainted_places,
visited_bbs
));
}
return ret_vec;
Expand Down Expand Up @@ -268,6 +277,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
after_comparison,
tainted_places,
visited_bbs
));
}
}
Expand All @@ -280,6 +290,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
after_comparison,
tainted_places,
visited_bbs
));
}
TerminatorKind::Yield { resume, .. } => {
Expand All @@ -289,6 +300,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
after_comparison,
tainted_places,
visited_bbs
));
}
TerminatorKind::FalseEdge { real_target, .. }
Expand All @@ -299,6 +311,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
after_comparison,
tainted_places,
visited_bbs
));
}
TerminatorKind::InlineAsm { destination, .. } => {
Expand All @@ -309,6 +322,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedMappingOperation {
caller_and_map_ops,
after_comparison,
tainted_places,
visited_bbs
));
}
}
Expand Down

0 comments on commit bc618fd

Please sign in to comment.