Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASM] Extend locking to cover _disposed member variable #6319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tracer/src/Datadog.Trace/AppSec/Waf/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ private Context(IntPtr contextHandle, Waf waf, WafLibraryInvoker wafLibraryInvok

private unsafe IResult? RunInternal(IDictionary<string, object>? persistentAddressData, IDictionary<string, object>? ephemeralAddressData, ulong timeoutMicroSeconds, bool isRasp = false)
{
if (_disposed)
{
Log.Information("Can't run WAF when context is disposed");
return null;
}

DdwafResultStruct retNative = default;

if (_waf.Disposed)
Expand All @@ -95,6 +89,12 @@ private Context(IntPtr contextHandle, Waf waf, WafLibraryInvoker wafLibraryInvok
WafReturnCode code;
lock (_stopwatch)
{
if (_disposed)
{
Log.Information("Can't run WAF when context is disposed");
return null;
}

// NOTE: the WAF must be called with either pwPersistentArgs or pwEphemeralArgs (or both) pointing to
// a valid structure. Failure to do so, results in a WAF error. It doesn't makes sense to propagate this
// error.
Expand Down Expand Up @@ -151,21 +151,21 @@ private Context(IntPtr contextHandle, Waf waf, WafLibraryInvoker wafLibraryInvok

public void Dispose(bool disposing)
{
if (_disposed)
lock (_stopwatch)
{
return;
}
if (_disposed)
{
return;
}

_disposed = true;
_disposed = true;

// WARNING do not move this above, this should only be disposed in the end of the context's life
foreach (var encodeResult in _encodeResults)
{
encodeResult.Dispose();
}
// WARNING do not move this above, this should only be disposed in the end of the context's life
foreach (var encodeResult in _encodeResults)
{
encodeResult.Dispose();
}

lock (_stopwatch)
{
_wafLibraryInvoker.ContextDestroy(_contextHandle);
}
}
Expand Down
Loading