Skip to content

Commit bae767c

Browse files
arthaudfacebook-github-bot
authored andcommitted
Factor out the function that computes features to attach
Summary: We currently have two functions that extract features to attach, let's factor them out. Reviewed By: dkgi Differential Revision: D30758332 fbshipit-source-id: ef81a82e75ba4111573a59460d32f31d1ae18338
1 parent 4a8df7e commit bae767c

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

source/interprocedural_analyses/taint/backwardAnalysis.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,8 +1429,9 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
14291429
in
14301430
let taint_in_taint_out =
14311431
let features_to_attach =
1432-
BackwardState.compute_features_to_attach
1432+
BackwardState.extract_features_to_attach
14331433
~root:parameter
1434+
~attach_to_leaf:Sinks.Attach
14341435
existing_backward.TaintResult.Backward.taint_in_taint_out
14351436
in
14361437
let candidate_tree =
@@ -1490,8 +1491,9 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
14901491
in
14911492
let sink_taint =
14921493
let features_to_attach =
1493-
BackwardState.compute_features_to_attach
1494+
BackwardState.extract_features_to_attach
14941495
~root:parameter
1496+
~attach_to_leaf:Sinks.Attach
14951497
existing_backward.TaintResult.Backward.sink_taint
14961498
in
14971499
if not (Features.SimpleSet.is_bottom features_to_attach) then

source/interprocedural_analyses/taint/domains.ml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -705,30 +705,25 @@ module MakeTaintEnvironment (Taint : TAINT_DOMAIN) () = struct
705705
let is_empty = is_bottom
706706
707707
let roots environment = fold Key ~f:List.cons ~init:[] environment
708-
end
709-
710-
module ForwardState = MakeTaintEnvironment (ForwardTaint) ()
711-
(** Used to infer which sources reach the exit points of a function. *)
712-
713-
(** Used to infer which sinks are reached from parameters, as well as the taint-in-taint-out (TITO)
714-
using the special LocalReturn sink. *)
715-
module BackwardState = struct
716-
include MakeTaintEnvironment (BackwardTaint) ()
717708
718-
let compute_features_to_attach ~root taint =
709+
let extract_features_to_attach ~root ~attach_to_leaf taint =
719710
let gather_features to_add features = Features.SimpleSet.add_set features ~to_add in
720711
read ~root ~path:[] taint
721712
|> Tree.collapse ~transform:Fn.id
722-
|> BackwardTaint.partition BackwardTaint.leaf ByFilter ~f:(fun sink ->
723-
if Sinks.equal Sinks.Attach sink then Some true else None)
713+
|> Taint.partition Taint.leaf ByFilter ~f:(fun leaf ->
714+
if Taint.equal_leaf attach_to_leaf leaf then Some true else None)
724715
|> (fun map -> Map.Poly.find map true)
725-
>>| BackwardTaint.fold
726-
BackwardTaint.simple_feature_self
727-
~f:gather_features
728-
~init:Features.SimpleSet.bottom
716+
>>| Taint.fold Taint.simple_feature_self ~f:gather_features ~init:Features.SimpleSet.bottom
729717
|> Option.value ~default:Features.SimpleSet.bottom
730718
end
731719
720+
module ForwardState = MakeTaintEnvironment (ForwardTaint) ()
721+
(** Used to infer which sources reach the exit points of a function. *)
722+
723+
module BackwardState = MakeTaintEnvironment (BackwardTaint) ()
724+
(** Used to infer which sinks are reached from parameters, as well as the taint-in-taint-out (TITO)
725+
using the special LocalReturn sink. *)
726+
732727
(* Special sink as it needs the return access path *)
733728
let local_return_taint =
734729
BackwardTaint.create

source/interprocedural_analyses/taint/forwardAnalysis.ml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,23 +1543,6 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
15431543
Fixpoint.Make (FixpointState)
15441544
end
15451545

1546-
let extract_features_to_attach existing_taint =
1547-
ForwardState.read ~root:AccessPath.Root.LocalResult ~path:[] existing_taint
1548-
|> ForwardState.Tree.collapse ~transform:Fn.id
1549-
|> ForwardTaint.partition ForwardTaint.leaf ByFilter ~f:(fun source ->
1550-
if Sources.equal Sources.Attach source then Some true else None)
1551-
|> (fun map -> Map.Poly.find map true)
1552-
|> function
1553-
| Some taint ->
1554-
let gather_features to_add features = Features.SimpleSet.add_set features ~to_add in
1555-
ForwardTaint.fold
1556-
ForwardTaint.simple_feature_self
1557-
~f:gather_features
1558-
~init:Features.SimpleSet.bottom
1559-
taint
1560-
| None -> Features.SimpleSet.bottom
1561-
1562-
15631546
let extract_source_model ~define ~resolution ~features_to_attach exit_taint =
15641547
let {
15651548
Statement.Define.signature =
@@ -1758,8 +1741,9 @@ let run ~environment ~qualifier ~define ~call_graph_of_define ~existing_model =
17581741
~port:AccessPath.Root.LocalResult
17591742
in
17601743
let features_to_attach =
1761-
BackwardState.compute_features_to_attach
1744+
BackwardState.extract_features_to_attach
17621745
~root:AccessPath.Root.LocalResult
1746+
~attach_to_leaf:Sinks.Attach
17631747
existing_model.TaintResult.backward.sink_taint
17641748
in
17651749
if not (Features.SimpleSet.is_bottom features_to_attach) then
@@ -1805,7 +1789,12 @@ let run ~environment ~qualifier ~define ~call_graph_of_define ~existing_model =
18051789
in
18061790
let resolution = TypeEnvironment.ReadOnly.global_resolution environment in
18071791
let extract_model { FixpointState.taint; _ } =
1808-
let features_to_attach = extract_features_to_attach existing_model.forward.source_taint in
1792+
let features_to_attach =
1793+
ForwardState.extract_features_to_attach
1794+
~root:AccessPath.Root.LocalResult
1795+
~attach_to_leaf:Sources.Attach
1796+
existing_model.forward.source_taint
1797+
in
18091798
let source_taint =
18101799
extract_source_model ~define:define.value ~resolution ~features_to_attach taint
18111800
in

0 commit comments

Comments
 (0)