Skip to content

Commit 1949d45

Browse files
authored
feat(asm): fix segmentation fault parsing JSON in Python2 (backport #4082) (#4096)
This is an automatic backport of pull request #4082 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details>
1 parent 658e64a commit 1949d45

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

ddtrace/appsec/_ddwaf.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def version():
5656

5757

5858
cdef inline object _string_to_bytes(object string, const char **ptr, ssize_t *length):
59+
ptr[0] = NULL
5960
if isinstance(string, six.binary_type):
6061
ptr[0] = PyBytes_AsString(string)
6162
length[0] = PyBytes_Size(string)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
ASM: fix Python 2 error reading WAF rules.

tests/appsec/test_processor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import pytest
55

6+
from ddtrace.appsec._ddwaf import DDWaf
67
from ddtrace.appsec.processor import AppSecSpanProcessor
8+
from ddtrace.appsec.processor import DEFAULT_RULES
79
from ddtrace.appsec.processor import _transform_headers
810
from ddtrace.constants import USER_KEEP
911
from ddtrace.contrib.trace_utils import set_http_meta
@@ -159,3 +161,9 @@ def test_appsec_span_rate_limit(tracer):
159161
assert span1.get_tag("_dd.appsec.json") is not None
160162
assert span2.get_tag("_dd.appsec.json") is not None
161163
assert span3.get_tag("_dd.appsec.json") is None
164+
165+
166+
def test_ddwaf_not_raises_exception():
167+
with open(DEFAULT_RULES) as rules:
168+
rules_json = json.loads(rules.read())
169+
DDWaf(rules_json)

0 commit comments

Comments
 (0)