[quandary] don't include taint_opt as part of formal_map

Reviewed By: jeremydubreil

Differential Revision: D4401887

fbshipit-source-id: 76e0fd8
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent ee2d0c9226
commit ddccb0cce1

@ -19,8 +19,8 @@ module Make (TaintSpecification : TaintSpec.S) = struct
module TaintDomain = TaintSpecification.AccessTree module TaintDomain = TaintSpecification.AccessTree
module IdMapDomain = IdAccessPathMapDomain module IdMapDomain = IdAccessPathMapDomain
(** a map from a formal to its position and (optionally) whether we should treat it as a source *) (** a map from a formal to its position *)
type formal_map = (int * TraceDomain.Source.t option) AccessPath.BaseMap.t type formal_map = int AccessPath.BaseMap.t
module Summary = Summary.Make(struct module Summary = Summary.Make(struct
type summary = QuandarySummary.t type summary = QuandarySummary.t
@ -78,11 +78,11 @@ module Make (TaintSpecification : TaintSpec.S) = struct
| Var.ProgramVar pvar -> Pvar.is_global pvar | Var.ProgramVar pvar -> Pvar.is_global pvar
| Var.LogicalVar _ -> false | Var.LogicalVar _ -> false
let make_footprint_var formal_num = let make_footprint_var formal_index =
Var.of_id (Ident.create_footprint Ident.name_spec formal_num) Var.of_id (Ident.create_footprint Ident.name_spec formal_index)
let make_footprint_access_path formal_num access_path = let make_footprint_access_path formal_index access_path =
AccessPath.with_base_var (make_footprint_var formal_num) access_path AccessPath.with_base_var (make_footprint_var formal_index) access_path
module TransferFunctions (CFG : ProcCfg.S) = struct module TransferFunctions (CFG : ProcCfg.S) = struct
module CFG = CFG module CFG = CFG
@ -109,14 +109,8 @@ module Make (TaintSpecification : TaintSpec.S) = struct
Some (TaintDomain.make_normal_leaf trace) in Some (TaintDomain.make_normal_leaf trace) in
let root, _ = AccessPath.extract access_path in let root, _ = AccessPath.extract access_path in
try try
let formal_num, taint_opt = AccessPath.BaseMap.find root proc_data.extras in let formal_index = AccessPath.BaseMap.find root proc_data.extras in
begin make_footprint_trace (make_footprint_access_path formal_index access_path)
match taint_opt with
| None ->
make_footprint_trace (make_footprint_access_path formal_num access_path)
| Some source ->
Some (TaintDomain.make_normal_leaf (TraceDomain.of_source source))
end
with Not_found -> with Not_found ->
if is_global root if is_global root
then make_footprint_trace access_path then make_footprint_trace access_path
@ -197,7 +191,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct
let add_sinks sinks actuals ({ Domain.access_tree; id_map; } as astate) proc_data callee_site = let add_sinks sinks actuals ({ Domain.access_tree; id_map; } as astate) proc_data callee_site =
let f_resolve_id = resolve_id id_map in let f_resolve_id = resolve_id id_map in
(* add [sink] to the trace associated with the [formal_num]th actual *) (* add [sink] to the trace associated with the [formal_index]th actual *)
let add_sink_to_actual access_tree_acc (sink_param : TraceDomain.Sink.parameter) = let add_sink_to_actual access_tree_acc (sink_param : TraceDomain.Sink.parameter) =
let actual_exp, actual_typ = IList.nth actuals sink_param.index in let actual_exp, actual_typ = IList.nth actuals sink_param.index in
match AccessPath.of_lhs_exp actual_exp actual_typ ~f_resolve_id with match AccessPath.of_lhs_exp actual_exp actual_typ ~f_resolve_id with
@ -243,11 +237,11 @@ module Make (TaintSpecification : TaintSpec.S) = struct
let apply_return ret_ap = match ret_opt with let apply_return ret_ap = match ret_opt with
| Some (ret_id, _) -> AccessPath.with_base_var (Var.of_id ret_id) ret_ap | Some (ret_id, _) -> AccessPath.with_base_var (Var.of_id ret_id) ret_ap
| None -> failwith "Have summary for retval, but no ret id to bind it to!" in | None -> failwith "Have summary for retval, but no ret id to bind it to!" in
let get_actual_ap formal_num = let get_actual_ap formal_index =
let f_resolve_id = resolve_id astate_in.id_map in let f_resolve_id = resolve_id astate_in.id_map in
try try
let actual_exp, actual_typ = let actual_exp, actual_typ =
IList.nth actuals formal_num in IList.nth actuals formal_index in
AccessPath.of_lhs_exp actual_exp actual_typ ~f_resolve_id AccessPath.of_lhs_exp actual_exp actual_typ ~f_resolve_id
with Failure _ -> with Failure _ ->
None in None in
@ -501,7 +495,7 @@ module Make (TaintSpecification : TaintSpec.S) = struct
(fun base node acc -> (fun base node acc ->
let base' = let base' =
try try
let formal_index, _ = AccessPath.BaseMap.find base formal_map in let formal_index = AccessPath.BaseMap.find base formal_map in
make_footprint_var formal_index, snd base make_footprint_var formal_index, snd base
with Not_found -> with Not_found ->
base in base in
@ -515,6 +509,23 @@ module Make (TaintSpecification : TaintSpec.S) = struct
let checker ({ Callbacks.tenv } as callback) = let checker ({ Callbacks.tenv } as callback) =
(* bind parameters to a trace with a tainted source (if applicable) *)
let make_initial pdesc =
let pname = Procdesc.get_proc_name pdesc in
let access_tree =
IList.fold_left (fun acc (name, typ, taint_opt) ->
match taint_opt with
| Some source ->
let base_ap = AccessPath.Exact (AccessPath.of_pvar (Pvar.mk name pname) typ) in
TaintDomain.add_trace base_ap (TraceDomain.of_source source) acc
| None ->
acc)
TaintDomain.empty
(TraceDomain.Source.get_tainted_formals pdesc tenv) in
if TaintDomain.BaseMap.is_empty access_tree
then Domain.empty
else { Domain.empty with Domain.access_tree; } in
let compute_post (proc_data : formal_map ProcData.t) = let compute_post (proc_data : formal_map ProcData.t) =
if not (Procdesc.did_preanalysis proc_data.pdesc) if not (Procdesc.did_preanalysis proc_data.pdesc)
then then
@ -522,7 +533,8 @@ module Make (TaintSpecification : TaintSpec.S) = struct
Preanal.do_liveness proc_data.pdesc proc_data.tenv; Preanal.do_liveness proc_data.pdesc proc_data.tenv;
Preanal.do_dynamic_dispatch proc_data.pdesc (Cg.create None) proc_data.tenv; Preanal.do_dynamic_dispatch proc_data.pdesc (Cg.create None) proc_data.tenv;
end; end;
match Analyzer.compute_post proc_data ~initial:Domain.empty with let initial = make_initial proc_data.pdesc in
match Analyzer.compute_post proc_data ~initial with
| Some { access_tree; } -> | Some { access_tree; } ->
Some (make_summary proc_data.extras access_tree) Some (make_summary proc_data.extras access_tree)
| None -> | None ->
@ -532,15 +544,15 @@ module Make (TaintSpecification : TaintSpec.S) = struct
let make_extras pdesc = let make_extras pdesc =
let pname = Procdesc.get_proc_name pdesc in let pname = Procdesc.get_proc_name pdesc in
let attrs = Procdesc.get_attributes pdesc in
let formals_with_nums = let formals_with_nums =
IList.mapi IList.mapi
(fun index (name, typ, taint_opt) -> (fun index (name, typ) ->
let pvar = Pvar.mk name pname in let pvar = Pvar.mk name pname in
AccessPath.base_of_pvar pvar typ, index, taint_opt) AccessPath.base_of_pvar pvar typ, index)
(TraceDomain.Source.get_tainted_formals pdesc tenv) in attrs.ProcAttributes.formals in
IList.fold_left IList.fold_left
(fun formal_map (base, index, taint_opt) -> (fun formal_map (base, index) -> AccessPath.BaseMap.add base index formal_map)
AccessPath.BaseMap.add base (index, taint_opt) formal_map)
AccessPath.BaseMap.empty AccessPath.BaseMap.empty
formals_with_nums in formals_with_nums in

Loading…
Cancel
Save