Skip to content

Commit

Permalink
Add ability to spread to frames not matching callee port and location
Browse files Browse the repository at this point in the history
Summary:
In some cases, for example, if the callee port and location doesn't match and the context providing frame is a partial flow that doesn't neccessarily intercept to the context recieving flow, let's still add the option to add the context breadcrumb to the trace frame.

This allows this feature to be re-used as adding a context feature to a callable when the callee ids and caller ids match.

The following flow was modelled here:

Crypto Init -> genEncrypt/Decrypt

This flow will have a via-crypto-project-value breadcrumb with the name of the crypto project.

This will be added to the two following flows:
1. User Controlled -> genDecrypt -> ReturnedToUser
2. User Controlled -> genEncrypt -> ReturnedToUser

If we model the first context flow as CryptoInit -> genEcncrypt -> ReturnedToUser, we add the breadcrumb to many trace frames which will add incorrect crypto project names if the flows (1 and 2) have some common trace frames among themselves.

With this feature, that is dealt with.

However, we still lack the capability to add the breadcrumb from trace frame to issue instance.

Reviewed By: fahndrich

Differential Revision: D62130425

fbshipit-source-id: c313764ac43d48f18f862277ed341c3877dc8f15
  • Loading branch information
Abishek V Ashok authored and facebook-github-bot committed Sep 26, 2024
1 parent 89a341e commit 4c11742
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sapp/pipeline/propagate_context_to_leaf_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class PropagateContextToLeafFrames(PipelineStep[TraceGraph, TraceGraph]):
pattern to all reachable leaf frames for a particular frame_kind."""

def __init__(
self, issue_code: int, feature_pattern: str, frame_kind: TraceKind
self,
issue_code: int,
feature_pattern: str,
frame_kind: TraceKind,
ignore_callee_port: bool = False,
) -> None:
super().__init__()
# pyre-fixme[13]: Attribute `summary` is never initialized.
Expand All @@ -48,6 +52,7 @@ def __init__(
)
self.leaf_features_added = 0
self.leaf_frames = 0
self.ignore_callee_port = ignore_callee_port

def _subtract_kinds(
self,
Expand Down Expand Up @@ -194,10 +199,12 @@ def _add_contextual_features_to_neighbor_frames(
)
is_root = self._is_root_port(trace_frame.caller_port)
for candidate in candidates:
if (
candidate.callee_location != trace_frame.callee_location
or candidate.callee_port != trace_frame.callee_port
or candidate.callee_id.local_id != trace_frame.callee_id.local_id
if candidate.callee_id.local_id != trace_frame.callee_id.local_id or (
(
candidate.callee_port != trace_frame.callee_port
or candidate.callee_location != trace_frame.callee_location
)
and (not self.ignore_callee_port)
):
continue

Expand Down

0 comments on commit 4c11742

Please sign in to comment.