text
stringlengths
0
601k
let loc_str ( rev , k ) = if rev then str " % d " k else str " +% d " k
let follow_str = function Name -> " name " | Descriptor -> " descriptor "
let verb_str = function Verbose -> " verbose " | Quiet -> " quiet "
let tail lines follow verb pid files = Printf . printf " lines = % s \ nfollow = % s \ nverb = % s \ npid = % s \ nfiles = % s \ n " ( loc_str lines ) ( opt_str follow_str follow ) ( verb_str verb ) ( opt_str string_of_int pid ) ( String . concat " , " files )
let loc_arg = let parse s = try if s <> " " && s . [ 0 ] <> ' ' + then Ok ( true , int_of_string s ) else Ok ( false , int_of_string ( String . sub s 1 ( String . length s - 1 ) ) ) with Failure _ -> Error ( ` Msg " unable to parse integer " ) in let print ppf p = Format . fprintf ppf " % s " ( loc_str p ) in Arg . con...
let lines = let doc = " Output the last ( $ docv ) lines or use ( $ i , ) ( +$ docv ) to start \ output after the ( $ i , N ) - 1th line . " in Arg . ( value & opt loc_arg ( true , 10 ) & info [ " n " ; " lines " ] ~ docv " : N " ~ doc )
let follow = let doc = " Output appended data as the file grows . ( $ docv ) specifies how \ the file should be tracked , by its ( $ b , name ) or by its \ ( $ b , descriptor ) . " in let follow = Arg . enum [ " name " , Name ; " descriptor " , Descriptor ] in Arg . ( value & opt ( some follow ) ~ vopt ( : Some Descrip...
let verb = let quiet = let doc = " Never output headers giving file names . " in Quiet , Arg . info [ " q " ; " quiet " ; " silent " ] ~ doc in let verbose = let doc = " Always output headers giving file names . " in Verbose , Arg . info [ " v " ; " verbose " ] ~ doc in Arg . ( last & vflag_all [ Quiet ] [ quiet ; verb...
let pid = let doc = " With - f , terminate after process ( $ docv ) dies . " in Arg . ( value & opt ( some int ) None & info [ " pid " ] ~ docv " : PID " ~ doc )
let files = Arg . ( value & ( pos_all non_dir_file [ ] ) & info [ ] ~ docv " : FILE " )
let cmd = let doc = " Display the last part of a file " in let man = [ ` S Manpage . s_description ; ` P " ( $ tname ) prints the last lines of each ( $ i , FILE ) to standard output . If no file is specified reads standard input . The number of printed lines can be specified with the ( $ b , - n ) option . " ; ` S Man...
let main ( ) = exit ( Cmd . eval cmd )
let ( ) = main ( )
let info = let doc = " Echo all messages consumed from a kafka topic " in let man = [ ` S " DESCRIPTION " ; ` P " ( $ tname ) prints all messages consumed from the kafka BROKERS along the topic TOPIC . " ; ` P " All partitions are consumed , unless a specific PARTITION is given . " ; ` P " Consumption starts from OFFSE...
let print_msg = function | Kafka . Message ( topic , partition , offset , msg , None ) -> Lwt_io . printf " % s , % d , % Ld ::% s \ n " %! ( Kafka . topic_name topic ) partition offset msg | Kafka . Message ( topic , partition , offset , msg , Some ( key ) ) -> Lwt_io . printf " % s , % d , % Ld :% s :% s \ n " %! ( K...
let tail_topic brokers msg_count timeout_ms topic_name partition offset = let consumer = Kafka . new_consumer [ " metadata . broker . list " , brokers ] in let topic = Kafka . new_topic consumer topic_name [ ] in let queue = Kafka . new_queue consumer in let partitions = match partition with | Some p -> [ p ] | None ->...
let brokers = let doc = " Kafka broker hosts ( comma sepated list of ' host : port ' ) " in Arg . ( value & opt string " localhost " & info [ " b " ; " brokers " ] ~ docv " : BROKERS " ~ doc )
let msg_count = let doc = " Count of messages to consume per batch . " in Arg . ( value & opt int 1024 & info [ " c " ; " count " ] ~ docv " : MSG_COUNT " ~ doc )
let timeout_ms = let doc = " Wait at most ( $ docv ) milli - seconds to fill a batch of the requested size . " in Arg . ( value & opt int 1000 & info [ " t " ; " timeout " ] ~ docv " : TIMEOUT_MS " ~ doc )
let offset = let doc = " The offset to start with . " in Arg . ( value & opt int64 0L & info [ " o " ; " offset " ] ~ docv " : OFFSET " ~ doc )
let topic = let doc = " The topic to consume . " in Arg . ( required & pos 0 ( some string ) None & info [ ] ~ docv " : TOPIC " ~ doc )
let partition = let doc = " The partition to consume . " in Arg . ( value & pos 1 ( some int ) None & info [ ] ~ docv " : PARTITION " ~ doc )
let tail_topic_t = Term . ( pure tail_topic $ brokers $ msg_count $ timeout_ms $ topic $ partition $ offset )
let ( ) = match Term . eval ( tail_topic_t , info ) with | ` Error _ -> exit 1 | _ -> exit 0
let is_sink varinfo = Cil . hasAttribute " taint_sink " varinfo . vattr
let is_source varinfo = Cil . hasAttribute " taint_source " varinfo . vattr
module Spec : Analyses . MCPSpec = struct include Analyses . DefaultSpec let name ( ) = " taint " module D = Lattice . Unit module C = Lattice . Unit let context _ _ = ( ) let rec is_exp_tainted ( state : D . t ) ( e : Cil . exp ) = match e with | AddrOf v | StartOf v | Lval v -> is_lval_tainted state v | BinOp ( _ , e...
let _ = MCP . register_analysis ( module Spec : MCPSpec )
let initialize_configuration ~ static_analysis_configuration : { Configuration . StaticAnalysis . configuration = { taint_model_paths ; _ } ; _ } = Log . info " Verifying model syntax and configuration . " ; let timer = Timer . start ( ) in ModelParser . get_model_sources ~ paths : taint_model_paths |> List . iter ~ f ...
let join_parse_result { ModelParser . models = models_left ; queries = queries_left ; skip_overrides = skip_overrides_left ; errors = errors_left ; } { ModelParser . models = models_right ; queries = queries_right ; skip_overrides = skip_overrides_right ; errors = errors_right ; } = { ModelParser . models = Registry . ...
let parse_models_and_queries_from_sources ~ static_analysis_configuration { : Configuration . StaticAnalysis . rule_filter ; _ } ~ scheduler ~ resolution ~ callables ~ stubs ~ taint_configuration sources = let map state sources = List . fold sources ~ init : state ~ f ( : fun state ( path , source ) -> ModelParser . pa...
let parse_models_and_queries_from_configuration ~ scheduler ~ static_analysis_configuration : ( { Configuration . StaticAnalysis . verify_models ; configuration = { taint_model_paths ; _ } ; rule_filter ; find_missing_flows ; dump_model_query_results ; maximum_trace_length ; maximum_tito_depth ; _ ; } as static_analysi...
let generate_models_from_queries ~ static_analysis_configuration { : Configuration . StaticAnalysis . rule_filter ; _ } ~ scheduler ~ environment ~ callables ~ stubs ~ taint_configuration ~ initial_models queries = let resolution = Analysis . TypeCheck . resolution ( Analysis . TypeEnvironment . ReadOnly . global_resol...
let initialize_models ~ scheduler ~ static_analysis_configuration ~ environment ~ callables ~ stubs = let stubs = Target . HashSet . of_list stubs in Log . info " Parsing taint models . . . " ; let timer = Timer . start ( ) in let { ModelParser . models ; queries ; skip_overrides ; errors } = parse_models_and_queries_f...
let run_taint_analysis ~ static_analysis_configuration : ( { Configuration . StaticAnalysis . configuration ; repository_root ; inline_decorators ; use_cache ; _ ; } as static_analysis_configuration ) ~ build_system ~ scheduler ( ) = try let ( ) = initialize_configuration ~ static_analysis_configuration in Service . St...
let common_breadcrumbs = [ | 131426483086725855 ; - 2325599749836791251 ; - 142622951265425597 ; 151405570984319626 ; 4041077761680409843 ; 2117647129174328834 ; 4007454346368129206 ; 2709449500254395549 ; - 293447484878671831 ; 3490955977576959699 ; - 2825441026312067324 ; 4137955276530861606 ; 3884789361536239432 ; 3...
let common_first_fields = [ | - 1579237068595228269 ; - 1181371377781863068 ; 2793234494828713258 ; 3529552762014010621 ; - 699490818662928217 ; - 3207755474630565726 ; 638136595512949422 ; 3489894656327767537 ; 1004614813458022908 ; 3167653849553134142 ; 1626021139687501307 ; - 2069201849497384383 ; 138587874777552066...
let common_first_indices = [ | - 3143217467817575195 ; 4465708301004234639 ; - 1579237068595228269 ; 3032728366906572078 ; 984833710289533319 ; 1626021139687501307 ; 2056574565062049424 ; - 834726256690366059 ; 1385878747775520664 ; - 2685695206115049921 ; - 1548986331894264544 ; - 1945631802289200782 ; 348989465632776...
module Rule = struct type t = { sources : Sources . t list ; sinks : Sinks . t list ; transforms : TaintTransform . t list ; code : int ; name : string ; message_format : string ; } [ @@ deriving compare , show ] end
type literal_string_sink = { pattern : Re2 . t ; sink_kind : Sinks . t ; }
type implicit_sinks = { conditional_test : Sinks . t list ; literal_string_sinks : literal_string_sink list ; }
let empty_implicit_sinks = { conditional_test = [ ] ; literal_string_sinks = [ ] }
type literal_string_source = { pattern : Re2 . t ; source_kind : Sources . t ; }
type implicit_sources = { literal_strings : literal_string_source list }
let empty_implicit_sources = { literal_strings = [ ] }
type analysis_model_constraints = { maximum_model_width : int ; maximum_return_access_path_length : int ; maximum_overrides_to_analyze : int option ; maximum_trace_length : int option ; maximum_tito_depth : int option ; }
let default_analysis_model_constraints = { maximum_model_width = 25 ; maximum_return_access_path_length = 10 ; maximum_overrides_to_analyze = None ; maximum_trace_length = None ; maximum_tito_depth = None ; }
type partial_sink_converter = ( Sources . t list * Sinks . t ) list String . Map . Tree . t
type missing_flows_kind = | Obscure | Type
let missing_flows_kind_from_string = function | " obscure " -> Some Obscure | " type " -> Some Type | _ -> None
let missing_flows_kind_to_string = function | Obscure -> " obscure " | Type -> " type "
type t = { sources : AnnotationParser . source_or_sink list ; sinks : AnnotationParser . source_or_sink list ; transforms : TaintTransform . t list ; features : string list ; rules : Rule . t list ; implicit_sinks : implicit_sinks ; implicit_sources : implicit_sources ; partial_sink_converter : partial_sink_converter ;...
let empty = { sources = [ ] ; sinks = [ ] ; transforms = [ ] ; features = [ ] ; rules = [ ] ; partial_sink_converter = String . Map . Tree . empty ; implicit_sinks = empty_implicit_sinks ; implicit_sources = empty_implicit_sources ; partial_sink_labels = String . Map . Tree . empty ; matching_sources = Sinks . Map . em...
module ConfigurationSharedMemory = Memory . WithCache . Make ( Memory . SingletonKey ) ( struct type nonrec t = t let prefix = Prefix . make ( ) let description = " Taint configuration " end )
module Error = struct type kind = | FileNotFound | FileRead | InvalidJson of string | NoConfigurationFound | UnexpectedJsonType of { json : Json . t ; message : string ; section : string option ; } | MissingKey of { key : string ; section : string ; } | UnknownKey of { key : string ; section : string ; } | UnsupportedS...
let transform_splits transforms = let rec split ~ result ~ prefix ~ suffix = let result = ( prefix , suffix ) :: result in match suffix with | [ ] -> result | next :: suffix -> split ~ result ~ prefix ( : next :: prefix ) ~ suffix in split ~ result [ ] : ~ prefix [ ] : ~ suffix : transforms
let matching_kinds_from_rules rules = let add_sources_sinks ( matching_sources , matching_sinks ) ( sources , sinks ) = let sinks_set = Sinks . Set . of_list sinks in let sources_set = Sources . Set . of_list sources in let update_matching_sources matching_sources sink = Sinks . Map . update sink ( function | None -> S...
let possible_tito_transforms_from_rules rules = let rec suffixes l = l :: Option . value_map ( List . tl l ) ~ default [ ] : ~ f : suffixes in let prefixes l = List . rev l |> suffixes |> List . map ~ f : List . rev in let substrings l = List . concat_map ( prefixes l ) ~ f : suffixes in List . concat_map rules ~ f ( :...
module PartialSinkConverter = struct let mangle { Sinks . kind ; label } = Format . sprintf " % s $% s " kind label let add map ~ first_sources ~ first_sinks ~ second_sources ~ second_sinks = let add map ( first_sink , second_sink ) = String . Map . Tree . add_multi map ~ key ( : mangle first_sink ) ~ data ( : first_so...
let parse source_jsons = let open Result in let json_exception_to_error ~ path ? section f = try f ( ) with | Json . Util . Type_error ( message , json ) | Json . Util . Undefined ( message , json ) -> Error [ Error . create ~ path ~ kind ( : Error . UnexpectedJsonType { json ; message ; section } ) ] in let json_bool_...
let validate ( { sources ; sinks ; transforms ; features ; _ } as configuration ) = let ensure_list_unique ~ get_name ~ get_error elements = let seen = String . Hash_set . create ( ) in let ensure_unique element = let element = get_name element in if Hash_set . mem seen element then Error [ { Error . path = None ; kind...
let exception_on_error = function | Ok configuration -> configuration | Error errors -> raise ( TaintConfigurationError errors )
let register configuration = let key = Memory . SingletonKey . key in let ( ) = if ConfigurationSharedMemory . mem key then ConfigurationSharedMemory . remove_batch ( ConfigurationSharedMemory . KeySet . singleton key ) in ConfigurationSharedMemory . add key configuration
let default = let sources = List . map ~ f ( : fun name -> { AnnotationParser . name ; kind = Named } ) [ " Demo " ; " Test " ; " UserControlled " ; " PII " ; " Secrets " ; " Cookies " ] in let sinks = List . map ~ f ( : fun name -> { AnnotationParser . name ; kind = Named } ) [ " Demo " ; " FileSystem " ; " GetAttr " ...
let obscure_flows_configuration configuration = let rules = [ { Rule . sources = List . map ~ f ( : fun { name = source ; _ } -> Sources . NamedSource source ) configuration . sources ; sinks = [ Sinks . NamedSink " Obscure " ] ; transforms = [ ] ; code = 9001 ; name = " Obscure flow . " ; message_format = " Data from ...
let missing_type_flows_configuration configuration = let rules = [ { Rule . sources = List . map ~ f ( : fun { name = source ; _ } -> Sources . NamedSource source ) configuration . sources ; sinks = [ Sinks . NamedSink " UnknownCallee " ] ; transforms = [ ] ; code = 9002 ; name = " Unknown callee flow . " ; message_for...
let apply_missing_flows configuration = function | Obscure -> obscure_flows_configuration configuration | Type -> missing_type_flows_configuration configuration
let get ( ) = match ConfigurationSharedMemory . get Memory . SingletonKey . key with | None -> default | Some configuration -> configuration
let create ~ rule_filter ~ find_missing_flows ~ dump_model_query_results_path ~ maximum_trace_length ~ maximum_tito_depth ~ taint_model_paths = let open Result in let file_paths = PyrePath . get_matching_files_recursively ~ suffix " . : config " ~ paths : taint_model_paths in let parse_configuration path = if not ( Pyr...
let conditional_test_sinks ( ) = match get ( ) with | { implicit_sinks = { conditional_test ; _ } ; _ } -> conditional_test
let literal_string_sinks ( ) = match get ( ) with | { implicit_sinks = { literal_string_sinks ; _ } ; _ } -> literal_string_sinks
let get_triggered_sink ~ partial_sink ~ source = let { partial_sink_converter ; _ } = get ( ) in PartialSinkConverter . get_triggered_sink partial_sink_converter ~ partial_sink ~ source
let is_missing_flow_analysis kind = match get ( ) with | { find_missing_flows ; _ } -> Option . equal [ % compare . equal : missing_flows_kind ] ( Some kind ) find_missing_flows
let get_maximum_model_width ( ) = match get ( ) with | { analysis_model_constraints = { maximum_model_width ; _ } ; _ } -> maximum_model_width
let literal_string_sources ( ) = let { implicit_sources ; _ } = get ( ) in implicit_sources . literal_strings
let get_maximum_overrides_to_analyze ( ) = let { analysis_model_constraints = { maximum_overrides_to_analyze ; _ } ; _ } = get ( ) in maximum_overrides_to_analyze
type analysis = | Forward | Backward
type step_event = { name : string ; seconds : float ; }
type statement_event = { statement : Statement . statement Node . t ; analysis : analysis ; seconds : float ; }
type fetch_model_event = { target : Interprocedural . Target . t ; analysis : analysis ; seconds : float ; model_words : int ; }
type profiler = { mutable step_events : step_event list ; mutable statement_events : statement_event list ; mutable fetch_model_events : fetch_model_event list ; timer : Timer . t ; }
type t = profiler option
let create ( ) = Some { step_events = [ ] ; statement_events = [ ] ; fetch_model_events = [ ] ; timer = Timer . start ( ) }
let track_duration ~ profiler ~ name ~ f = match profiler with | None -> f ( ) | Some profiler -> let timer = Timer . start ( ) in let result = f ( ) in let seconds = Timer . stop_in_sec timer in profiler . step_events <- { name ; seconds } :: profiler . step_events ; result
let track_statement_analysis ~ profiler ~ analysis ~ statement ~ f = match profiler with | None -> f ( ) | Some profiler -> let timer = Timer . start ( ) in let result = f ( ) in let seconds = Timer . stop_in_sec timer in profiler . statement_events <- { statement ; analysis ; seconds } :: profiler . statement_events ;...
let track_model_fetch ~ profiler ~ analysis ~ call_target ~ f = match profiler with | None -> f ( ) | Some profiler -> let timer = Timer . start ( ) in let model = f ( ) in let seconds = Timer . stop_in_sec timer in let model_words = model |> Obj . repr |> Obj . reachable_words in profiler . fetch_model_events <- { tar...
module StatementKey = struct type t = { statement : Statement . statement Node . t ; analysis : analysis ; } [ @@ deriving sexp , compare ] end
module StatementEventMap = Map . Make ( StatementKey )
module TargetKey = struct type t = { target : Interprocedural . Target . t ; analysis : analysis ; } [ @@ deriving sexp , compare ] end
module FetchModelEventMap = Map . Make ( TargetKey )
let dump = function | None -> ( ) | Some { step_events ; statement_events ; fetch_model_events ; timer } -> let total_seconds = Timer . stop_in_sec timer in Log . dump " Performance metrics " ; : Log . dump " Total time : . % 2fs " total_seconds ; let statement_events_seconds = List . fold ~ init : 0 . 0 ~ f ( : fun so...
let has_significant_summary ~ fixpoint_state ~ port : root ~ path ~ callee = match Fixpoint . get_model fixpoint_state callee with | None -> false | Some { Model . forward ; backward ; _ } -> ( match root with | AccessPath . Root . LocalResult -> let _ , tree = Domains . ForwardState . read_tree_raw ~ use_precise_label...
let issues_to_json ~ fixpoint_state ~ filename_lookup issues = let issue_to_json issue = let json = Issue . to_json ~ expand_overrides : true ~ is_valid_callee ( : has_significant_summary ~ fixpoint_state ) ~ filename_lookup issue in ` Assoc [ " kind " , ` String " issue " ; " data " , json ] in List . map ~ f : issue_...
let metadata ( ) = let codes = Issue . code_metadata ( ) in ` Assoc [ " codes " , codes ]
let statistics ( ) = let model_verification_errors = ModelVerificationError . get ( ) |> List . map ~ f : ModelVerificationError . to_json in ` Assoc [ " model_verification_errors " , ` List model_verification_errors ]
let extract_errors ~ scheduler ~ callables ~ fixpoint_state = let extract_errors callables = List . map ~ f ( : fun callable -> Fixpoint . get_result fixpoint_state callable |> List . map ~ f : Issue . to_error ) callables |> List . concat_no_order in Scheduler . map_reduce scheduler ~ policy ( : Scheduler . Policy . l...
let externalize ~ fixpoint_state ~ filename_lookup callable result model = let issues = issues_to_json ~ fixpoint_state ~ filename_lookup result in if not ( Model . should_externalize model ) then issues else Model . to_json ~ expand_overrides : true ~ is_valid_callee ( : has_significant_summary ~ fixpoint_state ) ~ fi...
let fetch_and_externalize ~ fixpoint_state ~ filename_lookup callable = let model = Fixpoint . get_model fixpoint_state callable |> Option . value ~ default : Model . empty_model in let result = Fixpoint . get_result fixpoint_state callable in externalize ~ fixpoint_state ~ filename_lookup callable result model
let emit_externalization ~ fixpoint_state ~ filename_lookup emitter callable = fetch_and_externalize ~ fixpoint_state ~ filename_lookup callable |> List . iter ~ f : emitter
let save_results_to_directory ~ result_directory ~ local_root ~ filename_lookup ~ skipped_overrides ~ callables ~ fixpoint_state ~ errors = let emit_json_array_elements out_buffer = let seen_element = ref false in fun json -> if ! seen_element then ( Bi_outbuf . add_string out_buffer " \ n " ; Json . to_outbuf out_buff...