88open Core
99open 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-
2111let location_to_json
2212 {
2313 Location. start = { line = start_line ; column = start_column } ;
@@ -265,11 +255,11 @@ end
265255module 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
309299end
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
322322end
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
332332end = 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
542542end
@@ -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
714714end
@@ -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);
0 commit comments