Skip to content

Commit

Permalink
fix: better None protection when tainting a grpc message (#9155)
Browse files Browse the repository at this point in the history
## Checklist

- [X] Change(s) are motivated and described in the PR description
- [X] Testing strategy is described if automated tests are not included
in the PR
- [X] Risks are described (performance impact, potential for breakage,
maintainability)
- [X] Change is maintainable (easy to change, telemetry, documentation)
- [X] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [X] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [X] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [X] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

---------

Signed-off-by: Juanjo Alvarez <[email protected]>
Co-authored-by: Brett Langdon <[email protected]>
(cherry picked from commit 434f711)
  • Loading branch information
juanjux authored and github-actions[bot] committed May 3, 2024
1 parent 89f69ae commit 58d2b87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ddtrace/contrib/grpc/client_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def _handle_response(span, response):
"grpc.response_message",
(response._response,),
)
if result and "response" in result:
response._response = result["response"].value
if result:
response_value = result.get("response")
if response_value:
response._response = response_value

if hasattr(response, "add_done_callback"):
response.add_done_callback(_future_done_callback(span))
Expand Down Expand Up @@ -173,8 +175,10 @@ def __next__(self):
"grpc.response_message",
(n,),
)
if result and "response" in result:
n = result["response"].value
if result:
response_value = result.get("response")
if response_value:
n = response_value
return n

next = __next__
Expand Down
3 changes: 3 additions & 0 deletions releasenotes/notes/asm-gprc-not-none-788b4b435b931a11.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixes:
- |
ASM: protect against potentially returning ``None`` when tainting a gRPC message.

0 comments on commit 58d2b87

Please sign in to comment.