Skip to content

Commit

Permalink
Protect Processor::Context#run with a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Apr 12, 2023
1 parent 650ba0c commit 20718a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/datadog/appsec/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ def initialize(processor)
@time_ext_ns = 0.0
@timeouts = 0
@events = []
@run_mutex = Mutex.new
end

def run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
@run_mutex.lock

start_ns = Core::Utils::Time.get_time(:nanosecond)

# TODO: remove multiple assignment
Expand All @@ -30,6 +33,8 @@ def run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
@timeouts += 1 if res.timeout

res
ensure
@run_mutex.unlock
end

def finalize
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/appsec/processor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Datadog

@context: WAF::Context

@run_mutex: ::Thread::Mutex

def initialize: (Processor processor) -> void
def run: (data input, ?::Integer timeout) -> WAF::Result
def finalize: () -> void
Expand Down

0 comments on commit 20718a5

Please sign in to comment.