diff --git a/infer/src/quandary/JavaTrace.ml b/infer/src/quandary/JavaTrace.ml index 0a2398644..dd6eddd56 100644 --- a/infer/src/quandary/JavaTrace.ml +++ b/infer/src/quandary/JavaTrace.ml @@ -185,4 +185,15 @@ include true | _ -> false + + let get_reportable_exn source sink passthroughs = + let pp_error fmt () = + F.fprintf + fmt + "Error: %a -> %a via %a" + Source.pp source Sink.pp sink Passthrough.Set.pp passthroughs in + let msg = "QUANDARY_TAINT_ERROR" in + let description = pp_to_string pp_error () in + Exceptions.Checkers (msg, Localise.verbatim_desc description) + end) diff --git a/infer/src/quandary/TaintAnalysis.ml b/infer/src/quandary/TaintAnalysis.ml index bf9f28bfe..bc5e71c5d 100644 --- a/infer/src/quandary/TaintAnalysis.ml +++ b/infer/src/quandary/TaintAnalysis.ml @@ -138,10 +138,10 @@ module Make (TraceDomain : QuandarySummary.Trace) = struct | Some (actual_trace, _) -> (* add callee_pname to actual trace as a sink *) let actual_trace' = TraceDomain.add_sink sink_param.sink actual_trace in - TraceDomain.log_reports - actual_trace' - (Cfg.Procdesc.get_proc_name proc_data.ProcData.pdesc) - loc; + let pname = Cfg.Procdesc.get_proc_name proc_data.ProcData.pdesc in + IList.iter + (Reporting.log_error pname ~loc) + (TraceDomain.get_reportable_exns actual_trace'); TaintDomain.add_trace actual_ap actual_trace' access_tree_acc | None -> access_tree_acc diff --git a/infer/src/quandary/Trace.ml b/infer/src/quandary/Trace.ml index 3c4f4dcc4..faa721f22 100644 --- a/infer/src/quandary/Trace.ml +++ b/infer/src/quandary/Trace.ml @@ -18,6 +18,9 @@ module type Spec = sig (** should a flow originating at source and entering sink be reported? *) val should_report : Source.t -> Sink.t -> bool + + (** get a loggable exception reporting a flow from source -> sink *) + val get_reportable_exn : Source.t -> Sink.t -> Passthrough.Set.t -> exn end module type S = sig @@ -35,8 +38,8 @@ module type S = sig (** get the reportable source-sink flows in this trace *) val get_reports : t -> (Source.t * Sink.t * Passthrough.Set.t) list - (** log the reportable source-sink flows in this trace *) - val log_reports : t -> Procname.t -> Location.t -> unit + (** get logging-ready exceptions for the reportable source-sink flows in this trace *) + val get_reportable_exns : t -> exn list (** create a trace from a source *) val of_source : Source.t -> t @@ -102,18 +105,10 @@ module Make (Spec : Spec) = struct else acc in Sources.fold (fun source acc -> Sinks.fold (report_one source) t.sinks acc) t.sources [] - let log_reports t pname loc = - let report_one (source, sink, passthroughs) = - let pp_error fmt () = - F.fprintf - fmt - "Error: %a -> %a via %a" - Source.pp source Sink.pp sink Passthrough.Set.pp passthroughs in - let msg = "QUANDARY_TAINT_ERROR" in - let description = pp_to_string pp_error () in - let exn = Exceptions.Checkers (msg, Localise.verbatim_desc description) in - Reporting.log_error pname exn ~loc in - IList.iter report_one (get_reports t) + let get_reportable_exns t = + IList.map + (fun (source, sink, passthroughs) -> Spec.get_reportable_exn source sink passthroughs) + (get_reports t) let of_source source = let sources = Sources.singleton source in diff --git a/infer/src/unit/TaintTests.ml b/infer/src/unit/TaintTests.ml index 593589605..29e4f9163 100644 --- a/infer/src/unit/TaintTests.ml +++ b/infer/src/unit/TaintTests.ml @@ -56,7 +56,9 @@ module MockTrace = Trace.Make(struct else [] end - let should_report _ _ = true + let should_report _ _ = false + + let get_reportable_exn _ _ _ = assert false end) module MockTaintAnalysis = TaintAnalysis.Make(struct diff --git a/infer/src/unit/TraceTests.ml b/infer/src/unit/TraceTests.ml index cabc1a04d..09d227669 100644 --- a/infer/src/unit/TraceTests.ml +++ b/infer/src/unit/TraceTests.ml @@ -76,6 +76,8 @@ module MockTrace = Trace.Make(struct let should_report source sink = Source.kind source = Sink.kind sink + + let get_reportable_exn _ _ _ = assert false end) let tests =