Skip to content

Commit 13819ce

Browse files
committed
Check array lengths to prevent OOB access
1 parent eb0c13c commit 13819ce

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

clippy_lints/src/explicit_write.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5555
if let ExprKind::MethodCall(ref write_fun, _, ref write_args) =
5656
unwrap_args[0].node;
5757
// Obtain the string that should be printed
58+
if write_args.len() > 1;
5859
if let ExprKind::Call(_, ref output_args) = write_args[1].node;
60+
if output_args.len() > 0;
5961
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].node;
6062
if let ExprKind::Array(ref string_exprs) = output_string_expr.node;
63+
if string_exprs.len() > 0;
6164
if let ExprKind::Lit(ref lit) = string_exprs[0].node;
6265
if let LitKind::Str(ref write_output, _) = lit.node;
6366
if write_fun.ident.name == "write_fmt";

0 commit comments

Comments
 (0)