diff --git a/infer/src/checkers/Source.ml b/infer/src/checkers/Source.ml index 7dc8c452a..ed5aa08ad 100644 --- a/infer/src/checkers/Source.ml +++ b/infer/src/checkers/Source.ml @@ -29,12 +29,6 @@ module type S = sig type spec = {source: t; index: int option} - val is_footprint : t -> bool - - val make_footprint : AccessPath.Abs.t -> Procdesc.t -> t - - val get_footprint_access_path : t -> AccessPath.Abs.t option - val get : CallSite.t -> HilExp.t list -> Tenv.t -> spec option val get_tainted_formals : Procdesc.t -> Tenv.t -> (Mangled.t * Typ.t * t option) list @@ -43,35 +37,15 @@ end module Make (Kind : Kind) = struct module Kind = Kind - type kind = - | Normal of Kind.t (** known source returned directly or transitively from a callee *) - | Footprint of AccessPath.Abs.t (** unknown source read from the environment *) - [@@deriving compare] - - let pp_kind fmt = function - | Normal kind - -> Kind.pp fmt kind - | Footprint ap - -> F.fprintf fmt "Footprint(%a)" AccessPath.Abs.pp ap - - type t = {kind: kind; site: CallSite.t} [@@deriving compare] + type t = {kind: Kind.t; site: CallSite.t} [@@deriving compare] type spec = {source: t; index: int option} - let is_footprint t = match t.kind with Footprint _ -> true | _ -> false - - let get_footprint_access_path t = match t.kind with Footprint ap -> Some ap | _ -> None - let call_site t = t.site - let kind t = match t.kind with Normal kind -> kind | Footprint _ -> Kind.unknown - - let make ?indexes:_ kind site = {site; kind= Normal kind} + let kind t = t.kind - let make_footprint ap pdesc = - let kind = Footprint ap in - let site = CallSite.make (Procdesc.get_proc_name pdesc) (Procdesc.get_loc pdesc) in - {site; kind} + let make ?indexes:_ kind site = {site; kind} let get site actuals tenv = match Kind.get (CallSite.pname site) actuals tenv with @@ -88,11 +62,9 @@ module Make (Kind : Kind) = struct (name, typ, Option.map kind_opt ~f:(fun kind -> make kind site))) (Kind.get_tainted_formals pdesc tenv) - let pp fmt s = F.fprintf fmt "%a(%a)" pp_kind s.kind CallSite.pp s.site + let pp fmt s = F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site - let with_callsite t callee_site = - if is_footprint t then failwithf "Can't change the call site of footprint source %a" pp t ; - {t with site= callee_site} + let with_callsite t callee_site = {t with site= callee_site} module Set = PrettyPrintable.MakePPSet (struct type nonrec t = t @@ -116,12 +88,6 @@ module Dummy = struct let pp _ () = () - let is_footprint _ = false - - let make_footprint _ _ = assert false - - let get_footprint_access_path _ = None - let get _ _ _ = None let get_tainted_formals pdesc _ = diff --git a/infer/src/checkers/Source.mli b/infer/src/checkers/Source.mli index f42b153b5..96a00dbbe 100644 --- a/infer/src/checkers/Source.mli +++ b/infer/src/checkers/Source.mli @@ -33,15 +33,6 @@ module type S = sig { source: t (** type of the returned source *) ; index: int option (** index of the returned source if Some; return value if None *) } - val is_footprint : t -> bool - (** return true if the current source is a footprint source *) - - val make_footprint : AccessPath.Abs.t -> Procdesc.t -> t - (** create a footprint source for the value read from the given access path. *) - - val get_footprint_access_path : t -> AccessPath.Abs.t option - (** return Some(access path) if the current source is a footprint source, None otherwise *) - val get : CallSite.t -> HilExp.t list -> Tenv.t -> spec option (** return Some (taint spec) if the call site with the given actuals is a taint source, None otherwise *) diff --git a/infer/src/checkers/Trace.ml b/infer/src/checkers/Trace.ml index baf24112e..5c6c60ce8 100644 --- a/infer/src/checkers/Trace.ml +++ b/infer/src/checkers/Trace.ml @@ -44,6 +44,8 @@ module type S = sig val of_source : Source.t -> t + val of_footprint : AccessPath.Abs.t -> t + val add : Source.t -> t -> t val get_footprint_indexes : t -> IntSet.t @@ -88,8 +90,11 @@ module type S = sig val of_source : Source.t -> t (** create a trace from a source *) + val of_footprint : AccessPath.Abs.t -> t + (** create a trace from a footprint access path *) + val add_source : Source.t -> t -> t - (** ad a source to the current trace *) + (** add a source to the current trace *) val add_sink : Sink.t -> t -> t (** add a sink to the current trace. *) @@ -183,26 +188,17 @@ module Make (Spec : Spec) = struct let is_empty {known; footprint} = Known.is_empty known && Footprint.BaseMap.is_empty footprint - let add_footprint_access_path access_path footprint = - Footprint.add_trace access_path true footprint + let of_footprint access_path = + let footprint = Footprint.add_trace access_path true Footprint.empty in + {empty with footprint} let of_source source = - match Source.get_footprint_access_path source with - | Some access_path - -> let footprint = add_footprint_access_path access_path Footprint.empty in - {empty with footprint} - | None - -> let known = Known.singleton source in - {empty with known} + let known = Known.singleton source in + {empty with known} let add source astate = - match Source.get_footprint_access_path source with - | Some access_path - -> let footprint = add_footprint_access_path access_path astate.footprint in - {astate with footprint} - | None - -> let known = Known.add source astate.known in - {astate with known} + let known = Known.add source astate.known in + {astate with known} let get_footprint_indexes {footprint} = Footprint.BaseMap.fold @@ -408,12 +404,19 @@ module Make (Spec : Spec) = struct ~f:(fun acc source -> trace_elems_of_source source acc) ~init:trace_prefix sources_with_level - let of_source source = - let sources = Sources.of_source source in + let of_sources sources = let passthroughs = Passthroughs.empty in let sinks = Sinks.empty in {sources; passthroughs; sinks} + let of_source source = + let sources = Sources.of_source source in + of_sources sources + + let of_footprint access_path = + let sources = Sources.of_footprint access_path in + of_sources sources + let add_source source t = let sources = Sources.add source t.sources in {t with sources} diff --git a/infer/src/checkers/Trace.mli b/infer/src/checkers/Trace.mli index 13a4b76d4..08c141847 100644 --- a/infer/src/checkers/Trace.mli +++ b/infer/src/checkers/Trace.mli @@ -46,6 +46,8 @@ module type S = sig val of_source : Source.t -> t + val of_footprint : AccessPath.Abs.t -> t + val add : Source.t -> t -> t val get_footprint_indexes : t -> IntSet.t @@ -91,8 +93,11 @@ module type S = sig val of_source : Source.t -> t (** create a trace from a source *) + val of_footprint : AccessPath.Abs.t -> t + (** create a trace from a footprint access path *) + val add_source : Source.t -> t -> t - (** ad a source to the current trace *) + (** add a source to the current trace *) val add_sink : Sink.t -> t -> t (** add a sink to the current trace. *) diff --git a/infer/src/quandary/ClangTrace.ml b/infer/src/quandary/ClangTrace.ml index 6ac095b6d..59eb8889f 100644 --- a/infer/src/quandary/ClangTrace.ml +++ b/infer/src/quandary/ClangTrace.ml @@ -246,18 +246,6 @@ include Trace.Make (struct | (Endpoint _ | EnvironmentVariable | File), Allocation -> (* untrusted data flowing to memory allocation *) true - | _, (Allocation | Other | ShellExec | SQL) when Source.is_footprint source - -> ( - (* is this var a command line flag created by the popular gflags library? *) - let is_gflag pvar = - String.is_substring ~substring:"FLAGS_" (Pvar.get_simplified_name pvar) - in - match Option.map ~f:AccessPath.Abs.extract (Source.get_footprint_access_path source) with - | Some ((Var.ProgramVar pvar, _), _) when Pvar.is_global pvar && is_gflag pvar - -> (* gflags globals come from the environment; treat them as sources *) - true - | _ - -> false ) | Other, _ -> (* Other matches everything *) true diff --git a/infer/src/quandary/JavaTrace.ml b/infer/src/quandary/JavaTrace.ml index cbdd98313..4d94a2284 100644 --- a/infer/src/quandary/JavaTrace.ml +++ b/infer/src/quandary/JavaTrace.ml @@ -317,9 +317,7 @@ include Trace.Make (struct module Sink = JavaSink let should_report source sink = - if Source.is_footprint source then false - else - match (Source.kind source, Sink.kind sink) with + match (Source.kind source, Sink.kind sink) with | PrivateData, Logging (* logging private data issue *) | Intent, StartComponent diff --git a/infer/src/quandary/TaintAnalysis.ml b/infer/src/quandary/TaintAnalysis.ml index 335e381ab..5a2493e96 100644 --- a/infer/src/quandary/TaintAnalysis.ml +++ b/infer/src/quandary/TaintAnalysis.ml @@ -42,10 +42,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct -> node_opt | None -> let make_footprint_trace footprint_ap = - let trace = - TraceDomain.of_source - (TraceDomain.Source.make_footprint footprint_ap proc_data.pdesc) - in + let trace = TraceDomain.of_footprint footprint_ap in Some (TaintDomain.make_normal_leaf trace) in let root, _ = AccessPath.Abs.extract access_path in diff --git a/infer/src/unit/TraceTests.ml b/infer/src/unit/TraceTests.ml index 3df384f82..9a421bc1d 100644 --- a/infer/src/unit/TraceTests.ml +++ b/infer/src/unit/TraceTests.ml @@ -118,13 +118,8 @@ let tests = let footprint_ap = AccessPath.Abs.Exact (AccessPath.of_id (Ident.create_none ()) (Typ.mk Tvoid)) in - let dummy_pdesc = - Cfg.create_proc_desc (Cfg.create_cfg ()) - (ProcAttributes.default Typ.Procname.empty_block !Config.curr_language) - in - let footprint_source = MockSource.make_footprint footprint_ap dummy_pdesc in let source_trace = MockTrace.of_source source1 in - let footprint_trace = MockTrace.of_source footprint_source |> MockTrace.add_sink sink1 in + let footprint_trace = MockTrace.of_footprint footprint_ap |> MockTrace.add_sink sink1 in let expected_trace = MockTrace.of_source source1 |> MockTrace.add_sink sink1 in assert_bool "Appended trace should contain source and sink" (trace_equal (MockTrace.append source_trace footprint_trace call_site) expected_trace)