Skip to content

Commit b10c8df

Browse files
authored
feat(asm): fix segmentation fault parsing JSON in Python2 (backport #4082) (#4094) (#4101)
* feat(asm): fix segmentation fault parsing JSON in Python2 (#4082) ## Description Fix Python 2 error reading WAF rules ## Checklist - [x] Title must conform to [conventional commit](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional). - [x] Add additional sections for `feat` and `fix` pull requests. - [x] Ensure tests are passing for affected code. ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] PR cannot be broken up into smaller PRs. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. - [ ] Add to milestone. (cherry picked from commit 399940a) # Conflicts: # tests/appsec/test_processor.py * feat: resolve cherrypick conflicts * feat: resolve cherrypick conflicts Co-authored-by: Alberto Vara <[email protected]> (cherry picked from commit a75815d) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 337410b commit b10c8df

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.ext import SpanTypes
810
from ddtrace.ext import priority
911
from tests.utils import override_env
@@ -75,3 +77,9 @@ def test_appsec_span_tags_snapshot(tracer):
7577
span.set_tag("http.status_code", "404")
7678

7779
assert "triggers" in json.loads(span.get_tag("_dd.appsec.json"))
80+
81+
82+
def test_ddwaf_not_raises_exception():
83+
with open(DEFAULT_RULES) as rules:
84+
rules_json = json.loads(rules.read())
85+
DDWaf(rules_json)

0 commit comments

Comments
 (0)