Skip to content

Commit 0312d34

Browse files
dromanolclaude
andcommitted
[AppSec] Free the WAF diagnostics of every config applied to the builder
ddwaf_builder_add_or_update_config allocates a fresh diagnostics object on every call and overwrites the one it is given without freeing it, so reusing a single object across the loop leaked all but the last one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 328c169 commit 0312d34

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tracer/src/Datadog.Trace/AppSec/Waf/Initialization/WafConfigurator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,18 @@ internal UpdateResult Update(IntPtr wafBuilderHandle, ConfigurationState configu
251251
{
252252
var configObj = encoded.ResultDdwafObject;
253253
var path = config.Key;
254-
if (!_wafLibraryInvoker.BuilderAddOrUpdateConfig(wafBuilderHandle, path, ref configObj, ref diagnostics))
254+
255+
// the WAF allocates a fresh diagnostics object on every call and overwrites the
256+
// one it is given without freeing it, so it can't be reused across the loop: only
257+
// the last one is reported, the previous ones have to be released here or they leak
258+
var configDiagnostics = default(DdwafObjectStruct);
259+
if (!_wafLibraryInvoker.BuilderAddOrUpdateConfig(wafBuilderHandle, path, ref configObj, ref configDiagnostics))
255260
{
256261
Log.Debug("WAF builder: Config failed to load : {0}", path); // Check were all these error codes are defined
257262
}
263+
264+
_wafLibraryInvoker.ObjectDestroy(ref diagnostics);
265+
diagnostics = configDiagnostics;
258266
}
259267
}
260268
}

0 commit comments

Comments
 (0)