From 66ef0ec0b95d30c7a692eb532480736e78850490 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Tue, 28 Jul 2015 08:44:15 -0600 Subject: [PATCH] [infer][reporting] Adding boilerplate for reporting Activity leaks --- infer/src/backend/errdesc.ml | 4 ++++ infer/src/backend/errdesc.mli | 3 +++ infer/src/backend/exceptions.ml | 3 +++ infer/src/backend/exceptions.mli | 1 + infer/src/backend/localise.ml | 6 ++++++ infer/src/backend/localise.mli | 3 +++ 6 files changed, 20 insertions(+) diff --git a/infer/src/backend/errdesc.ml b/infer/src/backend/errdesc.ml index 95e71c9e9..0c4c387f3 100644 --- a/infer/src/backend/errdesc.ml +++ b/infer/src/backend/errdesc.ml @@ -26,6 +26,10 @@ let hpred_is_open_resource prop = function | _ -> None +(** Produce a description of a persistent reference to an Android Activity *) +let explain_activity_leak activity_typ fieldname = + Localise.desc_activity_leak activity_typ fieldname + (** Explain a deallocate stack variable error *) let explain_deallocate_stack_var pvar ra = let pvar_str = pvar_to_string pvar in diff --git a/infer/src/backend/errdesc.mli b/infer/src/backend/errdesc.mli index 9744a7b3d..733c0b71d 100644 --- a/infer/src/backend/errdesc.mli +++ b/infer/src/backend/errdesc.mli @@ -40,6 +40,9 @@ val find_boolean_assignment : Cfg.Node.t -> Sil.pvar -> bool -> Cfg.Node.t optio (** describe rvalue [e] as a dexp *) val exp_rv_dexp : Cfg.Node.t -> Sil.exp -> Sil.dexp option +(** Produce a description of a persistent reference to an Android Activity *) +val explain_activity_leak : Sil.typ -> Ident.fieldname -> Localise.error_desc + (** Produce a description of a mismatch between an allocation function and a deallocation function *) val explain_allocation_mismatch : Sil.res_action -> Sil.res_action -> Localise.error_desc diff --git a/infer/src/backend/exceptions.ml b/infer/src/backend/exceptions.ml index 9fec8e468..16ee18944 100644 --- a/infer/src/backend/exceptions.ml +++ b/infer/src/backend/exceptions.ml @@ -30,6 +30,7 @@ type err_kind = Kwarning | Kerror | Kinfo exception Abduction_case_not_implemented of ml_location +exception Activity_leak of Localise.error_desc * ml_location exception Analysis_stops of Localise.error_desc * ml_location option exception Array_out_of_bounds_l1 of Localise.error_desc * ml_location exception Array_out_of_bounds_l2 of Localise.error_desc * ml_location @@ -87,6 +88,8 @@ let recognize_exception exn = let err_name, desc, mloco, visibility, severity, force_kind, eclass = match exn with (* all the names of Exn_user errors must be defined in Localise *) | Abduction_case_not_implemented mloc -> (Localise.from_string "Abduction_case_not_implemented", Localise.no_desc, Some mloc, Exn_developer, Low, None, Nocat) + | Activity_leak (desc, _) -> + (Localise.activity_leak, desc, None, Exn_user, High, None, Nocat) | Analysis_stops (desc, mloco) -> let visibility = if !Config.analysis_stops then Exn_user else Exn_developer in (Localise.analysis_stops, desc, mloco, visibility, Medium, None, Nocat) diff --git a/infer/src/backend/exceptions.mli b/infer/src/backend/exceptions.mli index 373042cbd..2e40ca0fc 100644 --- a/infer/src/backend/exceptions.mli +++ b/infer/src/backend/exceptions.mli @@ -30,6 +30,7 @@ type err_kind = type err_class = Checker | Prover | Nocat exception Abduction_case_not_implemented of ml_location +exception Activity_leak of Localise.error_desc * ml_location exception Analysis_stops of Localise.error_desc * ml_location option exception Array_of_pointsto of ml_location exception Array_out_of_bounds_l1 of Localise.error_desc * ml_location diff --git a/infer/src/backend/localise.ml b/infer/src/backend/localise.ml index 109145532..7e5b4cab7 100644 --- a/infer/src/backend/localise.ml +++ b/infer/src/backend/localise.ml @@ -28,6 +28,7 @@ let to_string s = s (** compare two localised strings *) let compare (s1: string) (s2: string) = Pervasives.compare s1 s2 +let activity_leak = "ACTIVITY_LEAK" let analysis_stops = "ANALYSIS_STOPS" let array_out_of_bounds_l1 = "ARRAY_OUT_OF_BOUNDS_L1" let array_out_of_bounds_l2 = "ARRAY_OUT_OF_BOUNDS_L2" @@ -363,6 +364,11 @@ let java_unchecked_exn_desc proc_name exn_name pre_str : error_desc = "can throw "^(Mangled.to_string exn_name); "whenever "^pre_str], None, []) +let desc_activity_leak activity_typ fieldname : error_desc = + let activity_str = Sil.typ_to_string activity_typ in + let fld_str = Ident.fieldname_to_string fieldname in + (["Activity subclass"; activity_str; "may leak via static field"; fld_str], None, []) + let desc_assertion_failure loc : error_desc = (["could be raised"; at_line (Tags.create ()) loc], None, []) diff --git a/infer/src/backend/localise.mli b/infer/src/backend/localise.mli index 0fb8d3671..b4296b2da 100644 --- a/infer/src/backend/localise.mli +++ b/infer/src/backend/localise.mli @@ -25,6 +25,7 @@ val to_string : t -> string (** compare two localised strings *) val compare : t -> t -> int +val activity_leak : t val analysis_stops : t val array_out_of_bounds_l1 : t val array_out_of_bounds_l2 : t @@ -189,6 +190,8 @@ val desc_null_test_after_dereference : string -> int -> Sil.location -> error_de val java_unchecked_exn_desc : Procname.t -> Mangled.t -> string -> error_desc +val desc_activity_leak : Sil.typ -> Ident.fieldname -> error_desc + (* Create human-readable error description for assertion failures *) val desc_assertion_failure : Sil.location -> error_desc