Skip to content

Commit

Permalink
Parse frame_type for extra_traces
Browse files Browse the repository at this point in the history
Summary:
This diff updates the mariana trench sapp parser to read "frame_type" from the json instead of defaulting to "tito_transform".
Note: This introduces a backwards incompatible change as we now expect the "frame_type" key to exist within an extra-trace json. This should not be a problem as we release the binary and `mariana_trench.tools` fbpkg with the zoncolan-cli together. Expect to fail if running on results from the older analysis binary.

Reviewed By: yuhshin-oss

Differential Revision: D57893393

fbshipit-source-id: 02143ba2da51018286b07aaf0d283a208d8fb452
  • Loading branch information
Anwesh Tuladhar authored and facebook-github-bot committed May 30, 2024
1 parent 961d472 commit f7045a0
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 4 deletions.
16 changes: 13 additions & 3 deletions sapp/pipeline/mariana_trench_parser_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def is_origin(self) -> bool:
def is_propagation_without_trace(self) -> bool:
return "Propagation" == self.call_kind

def is_propagation_with_trace(self) -> bool:
return "PropagationWithTrace" in self.call_kind


class LocalPositions(NamedTuple):
positions: List[Position]
Expand Down Expand Up @@ -257,16 +260,19 @@ def to_sapp_as_parsetracefeature(self) -> List[sapp.ParseTraceFeature]:
class ExtraTrace(NamedTuple):
kind: str
callee: CallInfo
frame_type: str

@staticmethod
def from_json(
extra_trace: Dict[str, Any], caller_position: Position
) -> "ExtraTrace":
frame_type = extra_trace["frame_type"]
return ExtraTrace(
kind=extra_trace["kind"],
callee=CallInfo.from_json(
extra_trace["call_info"], "sink", caller_position
extra_trace["call_info"], frame_type, caller_position
),
frame_type=frame_type,
)

def to_sapp(self) -> sapp.ParseTraceAnnotation:
Expand All @@ -284,8 +290,12 @@ def to_sapp(self) -> sapp.ParseTraceAnnotation:

return sapp.ParseTraceAnnotation(
location=self.callee.position.to_sapp(),
kind="tito_transform",
msg=f"Propagation through {self.kind}",
kind=self.frame_type,
msg=(
f"Propagation through {self.kind}"
if self.callee.is_propagation_with_trace()
else f"To {self.frame_type} kind: {self.kind}"
),
leaf_kind=self.kind,
leaf_depth=0,
type_interval=None,
Expand Down
102 changes: 101 additions & 1 deletion sapp/pipeline/tests/test_mariana_trench_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ParseIssueConditionTuple,
ParseIssueTuple,
ParseTraceAnnotation,
ParseTraceAnnotationSubtrace,
ParseTraceFeature,
ParseTypeInterval,
SourceLocation,
Expand Down Expand Up @@ -2293,6 +2294,7 @@ def testModelPropagations(self) -> None:
"path" : "ExtraTraces.java"
}
},
"frame_type": "sink",
"kind" : "T2:LocalReturn"
}
],
Expand Down Expand Up @@ -2337,7 +2339,7 @@ def testModelPropagations(self) -> None:
begin_column=1,
end_column=1,
),
kind="tito_transform",
kind="sink",
msg="Propagation through T2:LocalReturn",
leaf_kind="T2:LocalReturn",
leaf_depth=0,
Expand All @@ -2352,6 +2354,104 @@ def testModelPropagations(self) -> None:
],
)

# Parse callsite with source extra traces
self.assertParsed(
"""
{
"method" : "LClass;.rootCallable:(I)I",
"position" : { "line" : 42, "path" : "ExtraTraces.java" },
"effect_sinks" :
[
{
"port" : "call-chain",
"taint" :
[
{
"call_info" :
{
"call_kind" : "Origin",
"port" : "Argument(0)",
"position" :
{
"line" : 42,
"path" : "ExtraTraces.java"
}
},
"kinds" :
[
{
"extra_traces" :
[
{
"call_info" :
{
"call_kind" : "Origin",
"port" : "Return",
"position" :
{
"line" : 42,
"path" : "ExtraTraces.java"
}
},
"frame_type" : "source",
"kind" : "TestSource"
}
],
"kind" : "TestSource@TestSink",
"origins" :
[
{
"method" : "LClass;.toSink:(I)V",
"port" : "Argument(0)"
}
]
}
]
}
]
}
]
}
""",
[
ParseConditionTuple(
type=ParseType.PRECONDITION,
caller="LClass;.rootCallable:(I)I",
callee="LClass;.toSink:(I)V",
callee_location=SourceLocation(
line_no=42,
begin_column=1,
end_column=1,
),
filename="ExtraTraces.java",
titos=[],
leaves=[("TestSource@TestSink", 0)],
caller_port="call-chain",
callee_port="sink:argument(0)",
type_interval=None,
features=[],
annotations=[
ParseTraceAnnotation(
location=SourceLocation(
line_no=42,
begin_column=1,
end_column=1,
),
kind="source",
msg="To source kind: TestSource",
leaf_kind="TestSource",
leaf_depth=0,
type_interval=None,
link=None,
trace_key=None,
titos=[],
subtraces=[],
)
],
)
],
)

def testClassIntervals(self) -> None:
# Intervals at origin
self.assertParsed(
Expand Down

0 comments on commit f7045a0

Please sign in to comment.