Skip to content

Commit

Permalink
[IAST] Fix system test weak_cipher system test (#6034)
Browse files Browse the repository at this point in the history
## Summary of changes
Return first frame of the stack trace as location if no suitable one was
found, but no exclusion either

## Reason for change
System tests for weak cipher were broken due to a rare situation where
no location was detected for the vulnerability

## Implementation details
If no excluded frame was found, but the rest were skipped, we are
returning the first stack frame

## Test coverage
system tests should pass now
  • Loading branch information
daniel-romano-DD committed Sep 16, 2024
1 parent 909d318 commit 965a822
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions tracer/src/Datadog.Trace/Iast/IastModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ private static IastModuleResponse GetScope(string evidenceValue, IntegrationId i
private static Location? GetLocation(StackTrace? stack = null, Span? currentSpan = null)
{
stack ??= StackWalker.GetStackTrace();
var stackFrame = StackWalker.GetFrame(stack);
if (stackFrame is null)
if (!StackWalker.TryGetFrame(stack, out var stackFrame))
{
return null;
}
Expand Down
10 changes: 6 additions & 4 deletions tracer/src/Datadog.Trace/Iast/StackWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public static StackTrace GetStackTrace()
return new StackTrace(DefaultSkipFrames, true);
}

public static StackFrame? GetFrame(StackTrace stackTrace)
public static bool TryGetFrame(StackTrace stackTrace, out StackFrame? targetFrame)
{
targetFrame = null;
foreach (var frame in stackTrace.GetFrames())
{
var declaringType = frame?.GetMethod()?.DeclaringType;
Expand All @@ -62,18 +63,19 @@ public static StackTrace GetStackTrace()
{
if (excludeType == declaringType?.FullName)
{
return null;
return false;
}
}

var assembly = declaringType?.Assembly.GetName().Name;
if (assembly != null && !MustSkipAssembly(assembly))
{
return frame;
targetFrame = frame;
break;
}
}

return null;
return true;
}

public static bool MustSkipAssembly(string assembly)
Expand Down

0 comments on commit 965a822

Please sign in to comment.