Skip to content

Commit 9e16139

Browse files
committed
fix counting safe function call depth
1 parent 50e7201 commit 9e16139

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

expr_insecure.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ func (u *UntrustedInputChecker) OnVisitNodeEnter(n ExprNode) {
305305
func (u *UntrustedInputChecker) OnVisitNodeLeave(n ExprNode) {
306306
// Skip unsafe checks if we are inside of safe function call expression
307307
if u.safeCalls > 0 {
308+
if f, ok := n.(*FuncCallNode); ok && isSafeFuncCall(f) {
309+
u.safeCalls--
310+
}
308311
return
309312
}
310313

@@ -323,11 +326,6 @@ func (u *UntrustedInputChecker) OnVisitNodeLeave(n ExprNode) {
323326
u.onIndexAccess()
324327
case *ArrayDerefNode:
325328
u.onObjectFilter()
326-
case *FuncCallNode:
327-
if isSafeFuncCall(n) {
328-
u.safeCalls--
329-
}
330-
u.end()
331329
default:
332330
u.end()
333331
}

expr_insecure_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func testRunTrustedInputsCheckerForNode(t *testing.T, c *UntrustedInputChecker,
8282
}
8383
})
8484
c.OnVisitEnd()
85+
if c.safeCalls != 0 {
86+
t.Fatalf("%q safe calls counter is not zero: %d", input, c.safeCalls)
87+
}
8588
}
8689

8790
func TestExprInsecureDetectUntrustedValue(t *testing.T) {

0 commit comments

Comments
 (0)