[quandary] remove concept of a footprint source

Summary:
We now represent the footprint with an access trie, so this code is no longer required.
This lets us simplify things a bit

Reviewed By: jberdine

Differential Revision: D5664484

fbshipit-source-id: c35edf2
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent 94ceebfef8
commit fc828640ea

@ -29,12 +29,6 @@ module type S = sig
type spec = {source: t; index: int option} 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 : CallSite.t -> HilExp.t list -> Tenv.t -> spec option
val get_tainted_formals : Procdesc.t -> Tenv.t -> (Mangled.t * Typ.t * t option) list 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 Make (Kind : Kind) = struct
module Kind = Kind module Kind = Kind
type kind = type t = {kind: Kind.t; site: CallSite.t} [@@deriving compare]
| 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 spec = {source: t; index: int option} 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 call_site t = t.site
let kind t = match t.kind with Normal kind -> kind | Footprint _ -> Kind.unknown let kind t = t.kind
let make ?indexes:_ kind site = {site; kind= Normal kind}
let make_footprint ap pdesc = let make ?indexes:_ kind site = {site; kind}
let kind = Footprint ap in
let site = CallSite.make (Procdesc.get_proc_name pdesc) (Procdesc.get_loc pdesc) in
{site; kind}
let get site actuals tenv = let get site actuals tenv =
match Kind.get (CallSite.pname site) actuals tenv with 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))) (name, typ, Option.map kind_opt ~f:(fun kind -> make kind site)))
(Kind.get_tainted_formals pdesc tenv) (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 = let with_callsite t callee_site = {t with site= 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}
module Set = PrettyPrintable.MakePPSet (struct module Set = PrettyPrintable.MakePPSet (struct
type nonrec t = t type nonrec t = t
@ -116,12 +88,6 @@ module Dummy = struct
let pp _ () = () let pp _ () = ()
let is_footprint _ = false
let make_footprint _ _ = assert false
let get_footprint_access_path _ = None
let get _ _ _ = None let get _ _ _ = None
let get_tainted_formals pdesc _ = let get_tainted_formals pdesc _ =

@ -33,15 +33,6 @@ module type S = sig
{ source: t (** type of the returned source *) { source: t (** type of the returned source *)
; index: int option (** index of the returned source if Some; return value if None *) } ; 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 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 *) (** return Some (taint spec) if the call site with the given actuals is a taint source, None otherwise *)

@ -44,6 +44,8 @@ module type S = sig
val of_source : Source.t -> t val of_source : Source.t -> t
val of_footprint : AccessPath.Abs.t -> t
val add : Source.t -> t -> t val add : Source.t -> t -> t
val get_footprint_indexes : t -> IntSet.t val get_footprint_indexes : t -> IntSet.t
@ -88,8 +90,11 @@ module type S = sig
val of_source : Source.t -> t val of_source : Source.t -> t
(** create a trace from a source *) (** 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 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 val add_sink : Sink.t -> t -> t
(** add a sink to the current trace. *) (** 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 is_empty {known; footprint} = Known.is_empty known && Footprint.BaseMap.is_empty footprint
let add_footprint_access_path access_path footprint = let of_footprint access_path =
Footprint.add_trace access_path true footprint let footprint = Footprint.add_trace access_path true Footprint.empty in
{empty with footprint}
let of_source source = let of_source source =
match Source.get_footprint_access_path source with let known = Known.singleton source in
| Some access_path {empty with known}
-> 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 add source astate = let add source astate =
match Source.get_footprint_access_path source with let known = Known.add source astate.known in
| Some access_path {astate with known}
-> 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 get_footprint_indexes {footprint} = let get_footprint_indexes {footprint} =
Footprint.BaseMap.fold Footprint.BaseMap.fold
@ -408,12 +404,19 @@ module Make (Spec : Spec) = struct
~f:(fun acc source -> trace_elems_of_source source acc) ~f:(fun acc source -> trace_elems_of_source source acc)
~init:trace_prefix sources_with_level ~init:trace_prefix sources_with_level
let of_source source = let of_sources sources =
let sources = Sources.of_source source in
let passthroughs = Passthroughs.empty in let passthroughs = Passthroughs.empty in
let sinks = Sinks.empty in let sinks = Sinks.empty in
{sources; passthroughs; sinks} {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 add_source source t =
let sources = Sources.add source t.sources in let sources = Sources.add source t.sources in
{t with sources} {t with sources}

@ -46,6 +46,8 @@ module type S = sig
val of_source : Source.t -> t val of_source : Source.t -> t
val of_footprint : AccessPath.Abs.t -> t
val add : Source.t -> t -> t val add : Source.t -> t -> t
val get_footprint_indexes : t -> IntSet.t val get_footprint_indexes : t -> IntSet.t
@ -91,8 +93,11 @@ module type S = sig
val of_source : Source.t -> t val of_source : Source.t -> t
(** create a trace from a source *) (** 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 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 val add_sink : Sink.t -> t -> t
(** add a sink to the current trace. *) (** add a sink to the current trace. *)

@ -246,18 +246,6 @@ include Trace.Make (struct
| (Endpoint _ | EnvironmentVariable | File), Allocation | (Endpoint _ | EnvironmentVariable | File), Allocation
-> (* untrusted data flowing to memory allocation *) -> (* untrusted data flowing to memory allocation *)
true 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, _
-> (* Other matches everything *) -> (* Other matches everything *)
true true

@ -317,9 +317,7 @@ include Trace.Make (struct
module Sink = JavaSink module Sink = JavaSink
let should_report source sink = let should_report source sink =
if Source.is_footprint source then false match (Source.kind source, Sink.kind sink) with
else
match (Source.kind source, Sink.kind sink) with
| PrivateData, Logging | PrivateData, Logging
(* logging private data issue *) (* logging private data issue *)
| Intent, StartComponent | Intent, StartComponent

@ -42,10 +42,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct
-> node_opt -> node_opt
| None | None
-> let make_footprint_trace footprint_ap = -> let make_footprint_trace footprint_ap =
let trace = let trace = TraceDomain.of_footprint footprint_ap in
TraceDomain.of_source
(TraceDomain.Source.make_footprint footprint_ap proc_data.pdesc)
in
Some (TaintDomain.make_normal_leaf trace) Some (TaintDomain.make_normal_leaf trace)
in in
let root, _ = AccessPath.Abs.extract access_path in let root, _ = AccessPath.Abs.extract access_path in

@ -118,13 +118,8 @@ let tests =
let footprint_ap = let footprint_ap =
AccessPath.Abs.Exact (AccessPath.of_id (Ident.create_none ()) (Typ.mk Tvoid)) AccessPath.Abs.Exact (AccessPath.of_id (Ident.create_none ()) (Typ.mk Tvoid))
in 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 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 let expected_trace = MockTrace.of_source source1 |> MockTrace.add_sink sink1 in
assert_bool "Appended trace should contain source and sink" assert_bool "Appended trace should contain source and sink"
(trace_equal (MockTrace.append source_trace footprint_trace call_site) expected_trace) (trace_equal (MockTrace.append source_trace footprint_trace call_site) expected_trace)

Loading…
Cancel
Save