Skip to content

Commit

Permalink
feat(asm): fix segmentation fault parsing JSON in Python2 (backport #…
Browse files Browse the repository at this point in the history
…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 <alberto.vara@datadoghq.com>
(cherry picked from commit a75815d)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] committed Aug 16, 2022
1 parent 337410b commit b10c8df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddtrace/appsec/_ddwaf.pyx
Expand Up @@ -56,6 +56,7 @@ def version():


cdef inline object _string_to_bytes(object string, const char **ptr, ssize_t *length):
ptr[0] = NULL
if isinstance(string, six.binary_type):
ptr[0] = PyBytes_AsString(string)
length[0] = PyBytes_Size(string)
Expand Down
@@ -0,0 +1,4 @@
---
fixes:
- |
ASM: fix Python 2 error reading WAF rules.
8 changes: 8 additions & 0 deletions tests/appsec/test_processor.py
Expand Up @@ -3,7 +3,9 @@

import pytest

from ddtrace.appsec._ddwaf import DDWaf
from ddtrace.appsec.processor import AppSecSpanProcessor
from ddtrace.appsec.processor import DEFAULT_RULES
from ddtrace.ext import SpanTypes
from ddtrace.ext import priority
from tests.utils import override_env
Expand Down Expand Up @@ -75,3 +77,9 @@ def test_appsec_span_tags_snapshot(tracer):
span.set_tag("http.status_code", "404")

assert "triggers" in json.loads(span.get_tag("_dd.appsec.json"))


def test_ddwaf_not_raises_exception():
with open(DEFAULT_RULES) as rules:
rules_json = json.loads(rules.read())
DDWaf(rules_json)

0 comments on commit b10c8df

Please sign in to comment.