Skip to content

Commit e4feee6

Browse files
arthaudfacebook-github-bot
authored andcommitted
Rename leaf into kind
Summary: The term `leaf` is pretty ambiguous in our codebase. It is used in very various ways: * To denote the source or sink kind (e.g, `UserControlled`). It is also called `leaf kind` sometimes. * To denote a leaf name, i.e the callable that originated a source or sink, i.e the first frame or last frame of the trace. * To denote a leaf taint, i.e the first frame or last frame of the trace. * To denote a leaf in a binary tree. To prevent confusion, I propose to rename the first use into `kind`. This is a lot more explicit in my opinion, and it is also the term we use in our user interface. Reviewed By: dkgi Differential Revision: D30758453 fbshipit-source-id: a99bf4c7883e19c35bd35e800d19b2e5e8b8ecd0
1 parent f60188f commit e4feee6

File tree

12 files changed

+103
-105
lines changed

12 files changed

+103
-105
lines changed

source/interprocedural_analyses/taint/backwardAnalysis.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
228228
| Some argument -> get_argument_taint ~resolution ~argument)
229229
| _ -> failwith "unexpected tito sink"
230230
in
231-
let compute_tito_depth leaf depth =
232-
match leaf with
231+
let compute_tito_depth kind depth =
232+
match kind with
233233
| Sinks.LocalReturn -> max depth (1 + tito_depth)
234234
| _ -> depth
235235
in
@@ -245,14 +245,14 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
245245
~f:breadcrumbs
246246
|> BackwardTaint.transform
247247
TraceLength.Self
248-
(Context (BackwardTaint.leaf, Map))
248+
(Context (BackwardTaint.kind, Map))
249249
~f:compute_tito_depth
250250
|> BackwardState.Tree.create_leaf
251251
|> BackwardState.Tree.prepend tito_path
252252
|> BackwardState.Tree.join taint)
253253
~init:argument_taint
254254
in
255-
BackwardTaint.partition BackwardTaint.leaf By ~f:Fn.id element
255+
BackwardTaint.partition BackwardTaint.kind By ~f:Fn.id element
256256
|> Map.Poly.fold ~f:compute_parameter_tito ~init:argument_taint
257257
in
258258
let add_tito_feature_and_position leaf_taint =
@@ -306,7 +306,7 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
306306
| { tito = Some AllTito; _ } -> BackwardState.Tree.bottom
307307
| { tito = Some (SpecificTito { sanitized_tito_sinks; _ }); _ } ->
308308
BackwardState.Tree.partition
309-
BackwardTaint.leaf
309+
BackwardTaint.kind
310310
ByFilter
311311
~f:(fun sink ->
312312
Option.some_if (not (Sinks.Set.mem sink sanitized_tito_sinks)) sink)
@@ -322,7 +322,7 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
322322
match AccessPath.of_expression ~resolution argument with
323323
| Some { AccessPath.root; path } ->
324324
let features_to_add =
325-
BackwardState.Tree.filter_by_leaf ~leaf:Sinks.AddFeatureToArgument sink_taint
325+
BackwardState.Tree.filter_by_kind ~kind:Sinks.AddFeatureToArgument sink_taint
326326
|> BackwardTaint.fold
327327
BackwardTaint.simple_feature_self
328328
~f:Features.gather_breadcrumbs
@@ -1144,7 +1144,7 @@ module AnalysisInstance (FunctionContext : FUNCTION_CONTEXT) = struct
11441144
| { Sanitize.sinks = Some AllSinks; _ } -> BackwardState.Tree.empty
11451145
| { Sanitize.sinks = Some (SpecificSinks sanitized_sinks); _ } ->
11461146
BackwardState.Tree.partition
1147-
BackwardTaint.leaf
1147+
BackwardTaint.kind
11481148
ByFilter
11491149
~f:(fun sink ->
11501150
Option.some_if (not (Sinks.Set.mem sink sanitized_sinks)) sink)
@@ -1425,13 +1425,13 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
14251425
let annotation = original.Node.value.Parameter.annotation in
14261426
let partition =
14271427
BackwardState.read ~root:(Root.Variable name) ~path:[] entry_taint
1428-
|> BackwardState.Tree.partition BackwardTaint.leaf By ~f:Fn.id
1428+
|> BackwardState.Tree.partition BackwardTaint.kind By ~f:Fn.id
14291429
in
14301430
let taint_in_taint_out =
14311431
let features_to_attach =
14321432
BackwardState.extract_features_to_attach
14331433
~root:parameter
1434-
~attach_to_leaf:Sinks.Attach
1434+
~attach_to_kind:Sinks.Attach
14351435
existing_backward.TaintResult.Backward.taint_in_taint_out
14361436
in
14371437
let candidate_tree =
@@ -1493,7 +1493,7 @@ let extract_tito_and_sink_models define ~is_constructor ~resolution ~existing_ba
14931493
let features_to_attach =
14941494
BackwardState.extract_features_to_attach
14951495
~root:parameter
1496-
~attach_to_leaf:Sinks.Attach
1496+
~attach_to_kind:Sinks.Attach
14971497
existing_backward.TaintResult.Backward.sink_taint
14981498
in
14991499
if not (Features.SimpleSet.is_bottom features_to_attach) then

source/interprocedural_analyses/taint/domains.ml

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
open Core
99
open Ast
1010

11-
module type SET_ARG = sig
12-
include Abstract.SetDomain.ELEMENT
13-
14-
val equal : t -> t -> bool
15-
16-
val show : t -> string
17-
18-
val ignore_leaf_at_call : t -> bool
19-
end
20-
2111
let location_to_json
2212
{
2313
Location.start = { line = start_line; column = start_column };
@@ -265,11 +255,11 @@ end
265255
module type TAINT_DOMAIN = sig
266256
include Abstract.Domain.S
267257

268-
type leaf [@@deriving eq]
258+
type kind [@@deriving eq]
269259

270-
val leaf : leaf Abstract.Domain.part
260+
val kind : kind Abstract.Domain.part
271261

272-
val ignore_leaf_at_call : leaf -> bool
262+
val ignore_kind_at_call : kind -> bool
273263

274264
val trace_info : TraceInfo.t Abstract.Domain.part
275265

@@ -308,61 +298,71 @@ module type TAINT_DOMAIN = sig
308298
val to_external_json : filename_lookup:(Reference.t -> string option) -> t -> Yojson.Safe.json
309299
end
310300

311-
module LeafTaint (Leaf : SET_ARG) = struct
301+
module type KIND_ARG = sig
302+
include Abstract.SetDomain.ELEMENT
303+
304+
val equal : t -> t -> bool
305+
306+
val show : t -> string
307+
308+
val ignore_kind_at_call : t -> bool
309+
end
310+
311+
module KindTaint (Kind : KIND_ARG) = struct
312312
module Key = struct
313-
include Leaf
313+
include Kind
314314

315315
let absence_implicitly_maps_to_bottom = false
316316
end
317317

318318
module Map = Abstract.MapDomain.Make (Key) (FlowDetails)
319319
include Map
320320

321-
let singleton leaf = Map.set Map.bottom ~key:leaf ~data:FlowDetails.initial
321+
let singleton kind = Map.set Map.bottom ~key:kind ~data:FlowDetails.initial
322322
end
323323

324-
module MakeTaint (Leaf : SET_ARG) : sig
325-
include TAINT_DOMAIN with type leaf = Leaf.t
324+
module MakeTaint (Kind : KIND_ARG) : sig
325+
include TAINT_DOMAIN with type kind = Kind.t
326326

327-
val leaves : t -> leaf list
327+
val kinds : t -> kind list
328328

329-
val singleton : ?location:Location.WithModule.t -> leaf -> t
329+
val singleton : ?location:Location.WithModule.t -> kind -> t
330330

331-
val of_list : ?location:Location.WithModule.t -> leaf list -> t
331+
val of_list : ?location:Location.WithModule.t -> kind list -> t
332332
end = struct
333333
module Key = struct
334334
include TraceInfo
335335

336336
let absence_implicitly_maps_to_bottom = true
337337
end
338338

339-
module LeafDomain = LeafTaint (Leaf)
340-
module Map = Abstract.MapDomain.Make (Key) (LeafDomain)
339+
module KindTaintDomain = KindTaint (Kind)
340+
module Map = Abstract.MapDomain.Make (Key) (KindTaintDomain)
341341
include Map
342342

343-
type leaf = Leaf.t [@@deriving compare]
343+
type kind = Kind.t [@@deriving compare]
344344

345-
let equal_leaf = Leaf.equal
345+
let equal_kind = Kind.equal
346346

347-
let add ?location map leaf =
347+
let add ?location map kind =
348348
let trace =
349349
match location with
350350
| None -> TraceInfo.Declaration { leaf_name_provided = false }
351351
| Some location -> TraceInfo.Origin location
352352
in
353-
let leaf_taint = LeafDomain.singleton leaf in
353+
let kind_taint = KindTaintDomain.singleton kind in
354354
Map.update map trace ~f:(function
355-
| None -> leaf_taint
356-
| Some existing -> LeafDomain.join leaf_taint existing)
355+
| None -> kind_taint
356+
| Some existing -> KindTaintDomain.join kind_taint existing)
357357

358358

359-
let singleton ?location leaf = add ?location Map.bottom leaf
359+
let singleton ?location kind = add ?location Map.bottom kind
360360

361-
let of_list ?location leaves = List.fold leaves ~init:Map.bottom ~f:(add ?location)
361+
let of_list ?location kinds = List.fold kinds ~init:Map.bottom ~f:(add ?location)
362362

363-
let leaf = LeafDomain.Key
363+
let kind = KindTaintDomain.Key
364364

365-
let ignore_leaf_at_call = Leaf.ignore_leaf_at_call
365+
let ignore_kind_at_call = Kind.ignore_kind_at_call
366366

367367
let trace_info = Map.Key
368368

@@ -380,14 +380,14 @@ end = struct
380380

381381
let first_indices = Features.FirstIndexSet.Self
382382

383-
let leaves map =
384-
Map.fold leaf ~init:[] ~f:List.cons map |> List.dedup_and_sort ~compare:Leaf.compare
383+
let kinds map =
384+
Map.fold kind ~init:[] ~f:List.cons map |> List.dedup_and_sort ~compare:Kind.compare
385385

386386

387387
let create_json ~trace_info_to_json taint =
388-
let leaf_to_json trace_info (leaf, features) =
388+
let leaf_to_json trace_info (kind, features) =
389389
let trace_length = FlowDetails.fold TraceLength.Self features ~f:min ~init:55555 in
390-
let leaf_kind_json = `String (Leaf.show leaf) in
390+
let kind_json = `String (Kind.show kind) in
391391
let breadcrumbs, leaf_json =
392392
let gather_json { Abstract.OverUnderSetDomain.element; in_under } breadcrumbs =
393393
match element with
@@ -402,7 +402,7 @@ end = struct
402402
in
403403
let gather_return_access_path path leaves =
404404
let path_name = Abstract.TreeDomain.Label.show_path path in
405-
`Assoc ["kind", leaf_kind_json; "name", `String path_name; "depth", `Int trace_length]
405+
`Assoc ["kind", kind_json; "name", `String path_name; "depth", `Int trace_length]
406406
:: leaves
407407
in
408408
let breadcrumbs =
@@ -411,7 +411,7 @@ end = struct
411411
let leaves =
412412
FlowDetails.get FlowDetails.Slots.LeafName features
413413
|> Features.LeafNameSet.elements
414-
|> List.map ~f:(Features.LeafName.to_json ~leaf_kind_json)
414+
|> List.map ~f:(Features.LeafName.to_json ~kind_json)
415415
in
416416
let first_index_breadcrumbs =
417417
FlowDetails.get FlowDetails.Slots.FirstIndex features
@@ -439,7 +439,7 @@ end = struct
439439
let trace_json = trace_info_to_json ~trace_length trace_info in
440440
let leaf_json =
441441
if List.is_empty leaf_json then
442-
[`Assoc ["kind", leaf_kind_json]]
442+
[`Assoc ["kind", kind_json]]
443443
else
444444
leaf_json
445445
in
@@ -457,8 +457,8 @@ end = struct
457457
in
458458
`Assoc (trace_json :: association)
459459
in
460-
let trace_to_json (traceinfo, leaftaint) =
461-
LeafDomain.Map.to_alist leaftaint |> List.map ~f:(leaf_to_json traceinfo)
460+
let trace_to_json (trace_info, kind_taint) =
461+
KindTaintDomain.Map.to_alist kind_taint |> List.map ~f:(leaf_to_json trace_info)
462462
in
463463
(* expand now do dedup possibly abstract targets that resolve to the same concrete ones *)
464464
let taint = Map.transform Key Abstract.Domain.Map ~f:TraceInfo.expand_call_site taint in
@@ -494,29 +494,29 @@ end = struct
494494
let length = FlowDetails.get FlowDetails.Slots.TraceLength flow_details in
495495
TraceLength.is_bottom length || TraceLength.less_or_equal ~left:maximum_length ~right:length
496496
in
497-
transform LeafDomain.KeyValue Filter ~f:filter_flow
497+
transform KindTaintDomain.KeyValue Filter ~f:filter_flow
498498

499499

500500
let apply_call location ~callees ~port ~path ~element:taint =
501-
let apply (trace_info, leaf_taint) =
501+
let apply (trace_info, kind_taint) =
502502
let open TraceInfo in
503-
let leaf_taint =
504-
LeafDomain.transform
503+
let kind_taint =
504+
KindTaintDomain.transform
505505
Features.TitoPositionSet.Self
506506
Abstract.Domain.Map
507507
~f:(fun _ -> Features.TitoPositionSet.bottom)
508-
leaf_taint
508+
kind_taint
509509
in
510510
match trace_info with
511511
| Origin _
512512
| CallSite _ ->
513513
let increase_length n = if n < max_int then n + 1 else n in
514514
let trace_info = CallSite { location; callees; port; path } in
515-
let leaf_taint =
516-
leaf_taint
517-
|> LeafDomain.transform TraceLength.Self Abstract.Domain.Map ~f:increase_length
515+
let kind_taint =
516+
kind_taint
517+
|> KindTaintDomain.transform TraceLength.Self Abstract.Domain.Map ~f:increase_length
518518
in
519-
trace_info, leaf_taint
519+
trace_info, kind_taint
520520
| Declaration { leaf_name_provided } ->
521521
let trace_info = Origin location in
522522
let new_leaf_names =
@@ -529,14 +529,14 @@ end = struct
529529
in
530530
List.map ~f:make_leaf_name callees |> Features.LeafNameSet.of_list
531531
in
532-
let leaf_taint =
533-
LeafDomain.transform
532+
let kind_taint =
533+
KindTaintDomain.transform
534534
Features.LeafNameSet.Self
535535
Abstract.Domain.Add
536536
~f:new_leaf_names
537-
leaf_taint
537+
kind_taint
538538
in
539-
trace_info, leaf_taint
539+
trace_info, kind_taint
540540
in
541541
Map.transform Map.KeyValue Abstract.Domain.Map ~f:apply taint
542542
end
@@ -559,9 +559,9 @@ module MakeTaintTree (Taint : TAINT_DOMAIN) () = struct
559559
let transform_path (path, tip) =
560560
let tip =
561561
Taint.partition
562-
Taint.leaf
562+
Taint.kind
563563
ByFilter
564-
~f:(fun leaf -> if Taint.ignore_leaf_at_call leaf then None else Some false)
564+
~f:(fun kind -> if Taint.ignore_kind_at_call kind then None else Some false)
565565
tip
566566
|> (fun map -> Map.Poly.find map false)
567567
|> function
@@ -618,10 +618,10 @@ module MakeTaintTree (Taint : TAINT_DOMAIN) () = struct
618618
transform Taint.Self Map ~f:(Taint.prune_maximum_length maximum_length)
619619

620620

621-
let filter_by_leaf ~leaf taint_tree =
621+
let filter_by_kind ~kind taint_tree =
622622
collapse ~transform:Fn.id taint_tree
623-
|> Taint.partition Taint.leaf ByFilter ~f:(fun candidate ->
624-
if Taint.equal_leaf leaf candidate then Some true else None)
623+
|> Taint.partition Taint.kind ByFilter ~f:(fun candidate ->
624+
if Taint.equal_kind kind candidate then Some true else None)
625625
|> (fun map -> Map.Poly.find map true)
626626
|> Option.value ~default:Taint.bottom
627627

@@ -705,10 +705,10 @@ module MakeTaintEnvironment (Taint : TAINT_DOMAIN) () = struct
705705
706706
let roots environment = fold Key ~f:List.cons ~init:[] environment
707707
708-
let extract_features_to_attach ~root ~attach_to_leaf taint =
708+
let extract_features_to_attach ~root ~attach_to_kind taint =
709709
let gather_features to_add features = Features.SimpleSet.add_set features ~to_add in
710710
read ~root ~path:[] taint
711-
|> Tree.transform Taint.leaf Filter ~f:(Taint.equal_leaf attach_to_leaf)
711+
|> Tree.transform Taint.kind Filter ~f:(Taint.equal_kind attach_to_kind)
712712
|> Tree.collapse ~transform:Fn.id
713713
|> Taint.fold Taint.simple_feature_self ~f:gather_features ~init:Features.SimpleSet.bottom
714714
end
@@ -725,7 +725,7 @@ let local_return_taint =
725725
BackwardTaint.create
726726
[
727727
Part (BackwardTaint.trace_info, TraceInfo.Declaration { leaf_name_provided = false });
728-
Part (BackwardTaint.leaf, Sinks.LocalReturn);
728+
Part (BackwardTaint.kind, Sinks.LocalReturn);
729729
Part (TraceLength.Self, 0);
730730
Part (Features.ReturnAccessPathSet.Element, []);
731731
Part (Features.SimpleSet.Self, Features.SimpleSet.empty);

source/interprocedural_analyses/taint/features.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ module LeafName = struct
6767

6868
let show = Format.asprintf "%a" pp
6969

70-
let to_json ~leaf_kind_json { leaf; port } =
70+
let to_json ~kind_json { leaf; port } =
7171
let port_assoc =
7272
match port with
7373
| Some port -> ["port", `String port]
7474
| None -> []
7575
in
76-
`Assoc (port_assoc @ ["kind", leaf_kind_json; "name", `String leaf])
76+
`Assoc (port_assoc @ ["kind", kind_json; "name", `String leaf])
7777
end
7878

7979
module LeafNameSet = Abstract.SetDomain.Make (LeafName)

0 commit comments

Comments
 (0)