From 2babcc451a533e96f7c19dd5c8f1a8e4f350c4da Mon Sep 17 00:00:00 2001 From: czechbol Date: Wed, 28 Aug 2024 16:02:10 +0200 Subject: [PATCH] max recursion depth Signed-off-by: czechbol --- analyzers/conversion_overflow.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/analyzers/conversion_overflow.go b/analyzers/conversion_overflow.go index 5ccdcd8e28..27bccce4f4 100644 --- a/analyzers/conversion_overflow.go +++ b/analyzers/conversion_overflow.go @@ -168,9 +168,13 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool { return true } - // Recursive function to check predecessors - var checkPredecessors func(block *ssa.BasicBlock) bool - checkPredecessors = func(block *ssa.BasicBlock) bool { + // Recursive depth-first search of predecessor blocks of the SSA function to find bounds checks on the value being converted + var checkPredecessors func(block *ssa.BasicBlock, depth int) bool + checkPredecessors = func(block *ssa.BasicBlock, depth int) bool { + if depth > maxDepth { + return false + } + for _, pred := range block.Preds { minChecked, maxChecked := checkBlockForRangeCheck(pred, instr, dstInt) @@ -180,7 +184,7 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool { if minBoundChecked && maxBoundChecked { return true } - if checkPredecessors(pred) { + if checkPredecessors(pred, depth+1) { return true } } @@ -188,7 +192,7 @@ func hasExplicitRangeCheck(instr *ssa.Convert, dstType string) bool { } // Start checking from the initial block - checkPredecessors(block) + checkPredecessors(block, 0) if minBoundChecked && maxBoundChecked { return true