Skip to content

Commit 4f2a574

Browse files
committed
fix(filter): Call stack frame bound checks
Add more defensive checks against frame bounds to prevent accessing the frame that is out of bounds of the callstack.
1 parent 21eb54b commit 4f2a574

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pkg/filter/accessor_windows.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,12 @@ func callstackFields(field string, kevt *kevent.Kevent) (kparams.Value, error) {
667667
if kevt.Callstack.IsEmpty() {
668668
return nil, nil
669669
}
670+
670671
key, segment := captureInBrackets(field)
671672
if key == "" || segment == "" {
672673
return nil, nil
673674
}
675+
674676
var i int
675677
switch key {
676678
case frameUStart:
@@ -702,9 +704,13 @@ func callstackFields(field string, kevt *kevent.Kevent) (kparams.Value, error) {
702704
}
703705
}
704706

705-
if i > kevt.Callstack.Depth() || i < 0 {
707+
if i >= kevt.Callstack.Depth() {
708+
i = kevt.Callstack.Depth() - 1
709+
}
710+
if i < 0 {
706711
i = 0
707712
}
713+
708714
f := kevt.Callstack[i]
709715

710716
switch segment {

pkg/filter/filter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func TestThreadFilter(t *testing.T) {
368368
{`thread.callstack[uend].address = '7ffb5c1d0396'`, true},
369369
{`thread.callstack[kstart].address = 'fffff8072ebc1f6f'`, true},
370370
{`thread.callstack[kend].address = 'fffff8072eb8961b'`, true},
371-
{`thread.callstack[112222].address = '2638e59e0a5'`, true},
371+
{`thread.callstack[112222].address = 'fffff8072eb8961b'`, true},
372372
{`thread.callstack[2].symbol = 'Java_java_lang_ProcessImpl_create'`, true},
373373
{`thread.callstack[2].offset = 266`, true},
374374
{`thread.callstack[2].module = 'C:\\Program Files\\JetBrains\\GoLand 2021.2.3\\jbr\\bin\\java.dll'`, true},

0 commit comments

Comments
 (0)