From b61a34007ae613861434d19aa3e4a12004976631 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 15 Sep 2017 12:52:24 -0700 Subject: [PATCH] [thread-safety] re-enable check for calling non-threadsafe interface Reviewed By: jeremydubreil Differential Revision: D5843720 fbshipit-source-id: 29dd244 --- infer/src/checkers/ThreadSafety.ml | 5 +++-- infer/tests/codetoanalyze/java/threadsafety/Dispatch.java | 4 ++-- infer/tests/codetoanalyze/java/threadsafety/issues.exp | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index eecd42078..d43e0eb2a 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -1207,7 +1207,7 @@ let report_thread_safety_violation tenv pdesc ~make_description ~conflicts acces let trace_of_pname = trace_of_pname access pdesc in Option.iter ~f:report_one_path (PathDomain.get_reportable_sink_path access ~trace_of_pname) -let _report_unannotated_interface_violation tenv pdesc access reported_pname = +let report_unannotated_interface_violation tenv pdesc access reported_pname = match reported_pname with | Typ.Procname.Java java_pname -> let class_name = Typ.Procname.java_get_class_name java_pname in @@ -1343,9 +1343,10 @@ let report_unsafe_accesses aggregated_access_map = if is_duplicate_report access pname reported_acc then reported_acc else match (TraceElem.kind access, pre) with - | ( Access.InterfaceCall _ + | ( Access.InterfaceCall unannoted_call_pname , (AccessPrecondition.Unprotected _ | AccessPrecondition.TotallyUnprotected) ) -> (* un-annotated interface call + no lock. warn *) + report_unannotated_interface_violation tenv pdesc access unannoted_call_pname ; update_reported access pname reported_acc | Access.InterfaceCall _, AccessPrecondition.Protected _ -> (* un-annotated interface call, but it's protected by a lock/thread. don't report *) diff --git a/infer/tests/codetoanalyze/java/threadsafety/Dispatch.java b/infer/tests/codetoanalyze/java/threadsafety/Dispatch.java index 84004f7af..187144fb7 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/Dispatch.java +++ b/infer/tests/codetoanalyze/java/threadsafety/Dispatch.java @@ -35,11 +35,11 @@ class NotThreadSafe { @ThreadSafe public class Dispatch { - void FN_callUnannotatedInterfaceBad(UnannotatedInterface i) { + void callUnannotatedInterfaceBad(UnannotatedInterface i) { i.foo(); } - void FN_callUnannotatedInterfaceIndirectBad(NotThreadSafe s, UnannotatedInterface i) { + void callUnannotatedInterfaceIndirectBad(NotThreadSafe s, UnannotatedInterface i) { s.notThreadSafeOk(i); } diff --git a/infer/tests/codetoanalyze/java/threadsafety/issues.exp b/infer/tests/codetoanalyze/java/threadsafety/issues.exp index fdf0ae0d4..94cabb88e 100644 --- a/infer/tests/codetoanalyze/java/threadsafety/issues.exp +++ b/infer/tests/codetoanalyze/java/threadsafety/issues.exp @@ -53,6 +53,8 @@ codetoanalyze/java/threadsafety/DeDup.java, void DeDup.two_reads(), 3, THREAD_SA codetoanalyze/java/threadsafety/DeDup.java, void DeDup.two_writes(), 2, THREAD_SAFETY_VIOLATION, [access to `codetoanalyze.java.checkers.DeDup.field`] codetoanalyze/java/threadsafety/DeDup.java, void DeDup.write_read(), 2, THREAD_SAFETY_VIOLATION, [access to `codetoanalyze.java.checkers.DeDup.field`] codetoanalyze/java/threadsafety/DeDup.java, void DeDup.write_read(), 3, THREAD_SAFETY_VIOLATION, [,access to `codetoanalyze.java.checkers.DeDup.field`,,access to `codetoanalyze.java.checkers.DeDup.field`] +codetoanalyze/java/threadsafety/Dispatch.java, void Dispatch.callUnannotatedInterfaceBad(UnannotatedInterface), 1, THREAD_SAFETY_VIOLATION, [Call to un-annotated interface method void UnannotatedInterface.foo()1] +codetoanalyze/java/threadsafety/Dispatch.java, void Dispatch.callUnannotatedInterfaceIndirectBad(NotThreadSafe,UnannotatedInterface), 1, THREAD_SAFETY_VIOLATION, [call to void NotThreadSafe.notThreadSafeOk(UnannotatedInterface),Call to un-annotated interface method void UnannotatedInterface.foo()1] codetoanalyze/java/threadsafety/Locks.java, void Locks.FP_unlockOneLock(), 4, THREAD_SAFETY_VIOLATION, [access to `codetoanalyze.java.checkers.Locks.f`] codetoanalyze/java/threadsafety/Locks.java, void Locks.afterReentrantLockUnlockBad(), 3, THREAD_SAFETY_VIOLATION, [access to `codetoanalyze.java.checkers.Locks.f`] codetoanalyze/java/threadsafety/Locks.java, void Locks.afterUnlockBad(), 3, THREAD_SAFETY_VIOLATION, [access to `codetoanalyze.java.checkers.Locks.f`]