From fb950f7d287b2acd625937cc6a7c5c99e243c8e1 Mon Sep 17 00:00:00 2001 From: Flavien Darche <11708575+e-n-0@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:44:10 +0000 Subject: [PATCH] [ASM] iast: Fix for NullReferenceException in Stacktrace Walker (#6326) ## Summary of changes In .NET Framework the `GetFrames()` method can return null. ## Reason for change Bug detected in telemetry ([Error Tracking case](https://app.datadoghq.com/error-tracking?query=service%3Ainstrumentation-telemetry-data%20%40lib_language%3Adotnet%20%40tracer_version%3A3.6.0.0&fromUser=false&issue_states=&issueId=4ddc4722-7f47-11ef-afd5-da7ad0900002&refresh_mode=sliding&source=all&view=spans&from_ts=1732196777908&to_ts=1732211177908&live=true)). ## Implementation details Create a null array when the method `GetFrames()` return null in .NET Framework. --- tracer/src/Datadog.Trace/Iast/StackWalker.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tracer/src/Datadog.Trace/Iast/StackWalker.cs b/tracer/src/Datadog.Trace/Iast/StackWalker.cs index ff81a686fdf8..e34e87275ab6 100644 --- a/tracer/src/Datadog.Trace/Iast/StackWalker.cs +++ b/tracer/src/Datadog.Trace/Iast/StackWalker.cs @@ -55,7 +55,8 @@ public static StackTrace GetStackTrace() public static bool TryGetFrame(StackTrace stackTrace, out StackFrame? targetFrame) { targetFrame = null; - foreach (var frame in stackTrace.GetFrames()) + var frames = stackTrace.GetFrames() ?? []; + foreach (var frame in frames) { var declaringType = frame?.GetMethod()?.DeclaringType;