From 6113497020c375b5ceec3c9ce3bd486c619986ca Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Mon, 18 Apr 2016 08:32:59 -0700 Subject: [PATCH] delete callbackChecker and deps Reviewed By: cristianoc Differential Revision: D3187908 fb-gh-sync-id: ae78e9e fbshipit-source-id: ae78e9e --- infer/src/checkers/callbackChecker.ml | 115 ------------ infer/src/checkers/callbackChecker.mli | 14 -- infer/src/checkers/registerCheckers.ml | 1 - infer/src/harness/androidFramework.ml | 250 ------------------------- infer/src/harness/androidFramework.mli | 11 -- 5 files changed, 391 deletions(-) delete mode 100644 infer/src/checkers/callbackChecker.ml delete mode 100644 infer/src/checkers/callbackChecker.mli diff --git a/infer/src/checkers/callbackChecker.ml b/infer/src/checkers/callbackChecker.ml deleted file mode 100644 index 0e84d719b..000000000 --- a/infer/src/checkers/callbackChecker.ml +++ /dev/null @@ -1,115 +0,0 @@ -(* - * Copyright (c) 2013 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - *) - -open! Utils - -(** Make sure callbacks are always unregistered. drive the point home by reporting possible NPE's *) - -module L = Logging -module F = Format -module P = Printf -module IdSet = Ident.IdentSet -module FldSet = Ident.FieldSet - -(** set of instance fields belonging to the current file that are assigned to null literals *) -let fields_nullified = ref FldSet.empty - -(** set of callbacks registered in the current file *) -let registered_callback_procs = ref Procname.Set.empty - -let android_lifecycle_typs = ref [] - -(** resolve the list of android lifecycle type strings in [tenv] *) -let get_or_create_lifecycle_typs tenv = match !android_lifecycle_typs with - | [] -> - let lifecycle_typs = IList.fold_left (fun typs (pkg, clazz, methods) -> - let qualified_name = Mangled.from_package_class pkg clazz in - match AndroidFramework.get_lifecycle_for_framework_typ_opt - qualified_name methods tenv with - | Some (framework_typ, _) -> framework_typ :: typs - | None -> typs - ) [] AndroidFramework.get_lifecycles in - android_lifecycle_typs := lifecycle_typs; - lifecycle_typs - | typs -> typs - - -let num_methods_checked = ref 0 - -let done_checking num_methods = - incr num_methods_checked; - !num_methods_checked = num_methods - -(** ask Eradicate to check each of the procs in [registered_callback_procs] (and their transitive - * callees) in a context where each of the fields in [fields_nullifed] is marked as @Nullable *) -let do_eradicate_check ({ Callbacks.get_proc_desc } as callback_args) = - (* tell Eradicate to treat each of the fields nullified in on_destroy as nullable *) - FldSet.iter (fun fld -> Models.Inference.field_add_nullable_annotation fld) !fields_nullified; - Procname.Set.iter - (fun proc_name -> - match get_proc_desc proc_name with - | Some proc_desc -> - Eradicate.callback_eradicate - { callback_args with Callbacks.proc_name; proc_desc } - | None -> ()) - !registered_callback_procs - -(** if [procname] belongs to an Android lifecycle type, save the set of callbacks registered in - * [procname]. in addition, if [procname] is a special "destroy" /"cleanup" method, save the set of - * fields that are nullified *) -let callback_checker_main_java - proc_name_java ({ Callbacks.proc_desc; tenv } as callback_args) = - let typename = - Typename.TN_csu - (Csu.Class Csu.Java, - Mangled.from_string (Procname.java_get_class_name proc_name_java)) in - match Tenv.lookup tenv typename with - | Some ({ struct_name = Some _; def_methods } as struct_typ) -> - let typ = Sil.Tstruct struct_typ in - let lifecycle_typs = get_or_create_lifecycle_typs tenv in - let proc_belongs_to_lifecycle_typ = IList.exists - (fun lifecycle_typ -> AndroidFramework.typ_is_lifecycle_typ typ lifecycle_typ tenv) - lifecycle_typs in - if proc_belongs_to_lifecycle_typ then - (* TODO (tt4959422): get all of the callbacks registered by callees as well *) - let registered_callback_typs = - AndroidFramework.get_callbacks_registered_by_proc proc_desc tenv in - (* find the callbacks registered by this procedure and update the list *) - let registered_callback_procs' = IList.fold_left - (fun callback_procs callback_typ -> - match callback_typ with - | Sil.Tptr (Sil.Tstruct - { Sil.struct_name = Some _; def_methods = def_methods'}, _) -> - IList.fold_left - (fun callback_procs callback_proc -> - if Procname.is_constructor callback_proc then callback_procs - else Procname.Set.add callback_proc callback_procs) - callback_procs - def_methods' - | _ -> callback_procs) - !registered_callback_procs - registered_callback_typs in - registered_callback_procs := registered_callback_procs'; - let _ = if AndroidFramework.is_destroy_method callback_args.Callbacks.proc_name then - (* compute the set of fields nullified by this procedure *) - (* TODO (t4959422): get fields that are nullified in callees of the destroy method *) - fields_nullified := - FldSet.union (PatternMatch.get_fields_nullified proc_desc) !fields_nullified in - if done_checking (IList.length def_methods) then - do_eradicate_check callback_args - | _ -> () - - -let callback_checker_main - ({ Callbacks.proc_name } as callback_args) = - match proc_name with - | Procname.Java pname_java -> - callback_checker_main_java pname_java callback_args - | _ -> - () diff --git a/infer/src/checkers/callbackChecker.mli b/infer/src/checkers/callbackChecker.mli deleted file mode 100644 index 80643c0cf..000000000 --- a/infer/src/checkers/callbackChecker.mli +++ /dev/null @@ -1,14 +0,0 @@ -(* - * Copyright (c) 2013 - present Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - *) - -open! Utils - -(** Make sure callbacks are always unregistered. drive the point home by reporting possible NPE's *) - -val callback_checker_main : Callbacks.proc_callback_t diff --git a/infer/src/checkers/registerCheckers.ml b/infer/src/checkers/registerCheckers.ml index 03c86badf..3d7870c37 100644 --- a/infer/src/checkers/registerCheckers.ml +++ b/infer/src/checkers/registerCheckers.ml @@ -21,7 +21,6 @@ let active_procedure_checkers () = let java_checkers = let l = [ - CallbackChecker.callback_checker_main, false; Checkers.callback_check_access, false; Checkers.callback_monitor_nullcheck, false; Checkers.callback_test_state , false; diff --git a/infer/src/harness/androidFramework.ml b/infer/src/harness/androidFramework.ml index 22436bef7..95314524f 100644 --- a/infer/src/harness/androidFramework.ml +++ b/infer/src/harness/androidFramework.ml @@ -15,13 +15,6 @@ module TypSet = Sil.TypSet (** Android lifecycle types and their lifecycle methods that are called by the framework *) -(** work-in-progress list of known callback-registering method names *) -let callback_register_methods = - let method_list = ["addCallback"; "register"; "setOnClickListener"] in - IList.fold_left (fun set str -> StringSet.add str set) StringSet.empty method_list - -let is_known_callback_register_method proc_str = StringSet.mem proc_str callback_register_methods - let on_destroy = "onDestroy" let on_destroy_view = "onDestroyView" @@ -63,194 +56,6 @@ let android_lifecycles = fragment_lifecycle); ] -let android_callbacks = - let cb_strs = [ - ("android.accounts", "OnAccountsUpdateListener"); - ("android.animation", "Animator$AnimatorListener"); - ("android.animation", "LayoutTransition$TransitionListener"); - ("android.animation", "TimeAnimator$TimeListener"); - ("android.animation", "ValueAnimator$AnimatorUpdateListener"); - ("android.app", "ActionBar$OnMenuVisibilityListener"); - ("android.app", "ActionBar$OnNavigationListener"); - ("android.app", "ActionBar$TabListener"); - ("android.app", "Application$ActivityLifecycleCallbacks"); - ("android.app", "DatePickerDialog$OnDateSetListener"); - ("android.app", "FragmentBreadCrumbs$OnBreadCrumbClickListener"); - ("android.app", "FragmentManager$OnBackStackChangedListener"); - ("android.app", "KeyguardManager$OnKeyguardExitResult"); - ("android.app", "LoaderManager$LoaderCallbacks"); - ("android.app", "PendingIntent$OnFinished"); - ("android.app", "SearchManager$OnCancelListener"); - ("android.app", "SearchManager$OnDismissListener"); - ("android.app", "TimePickerDialog$OnTimeSetListener"); - ("android.bluetooth", "BluetoothProfile$ServiceListener"); - ("android.content", "ClipboardManager$OnPrimaryClipChangedListener"); - ("android.content", "ComponentCallbacks"); - ("android.content", "ComponentCallbacks2"); - ("android.content", "DialogInterface$OnCancelListener"); - ("android.content", "DialogInterface$OnClickListener"); - ("android.content", "DialogInterface$OnDismissListener"); - ("android.content", "DialogInterface$OnKeyListener"); - ("android.content", "DialogInterface$OnMultiChoiceClickListener"); - ("android.content", "DialogInterface$OnShowListener"); - ("android.content", "IntentSender$OnFinished"); - ("android.content", "Loader$OnLoadCanceledListener"); - ("android.content", "Loader$OnLoadCompleteListener"); - ("android.content", "SharedPreferences$OnSharedPreferenceChangeListener"); - ("android.content", "SyncStatusObserver"); - ("android.database.sqlite", "SQLiteTransactionListener"); - ("android.drm", "DrmManagerClient$OnErrorListener"); - ("android.drm", "DrmManagerClient$OnEventListener"); - ("android.drm", "DrmManagerClient$OnInfoListener"); - ("android.gesture", "GestureOverlayView$OnGestureListener"); - ("android.gesture", "GestureOverlayView$OnGesturePerformedListener"); - ("android.gesture", "GestureOverlayView$OnGesturingListener"); - ("android.graphics", "SurfaceTexture$OnFrameAvailableListener"); - ("android.hardware", "Camera$AutoFocusCallback"); - ("android.hardware", "Camera$AutoFocusMoveCallback"); - ("android.hardware", "Camera$ErrorCallback"); - ("android.hardware", "Camera$FaceDetectionListener"); - ("android.hardware", "Camera$OnZoomChangeListener"); - ("android.hardware", "Camera$PictureCallback"); - ("android.hardware", "Camera$PreviewCallback"); - ("android.hardware", "Camera$ShutterCallback"); - ("android.hardware", "SensorEventListener"); - ("android.hardware.display", "DisplayManager$DisplayListener"); - ("android.hardware.input", "InputManager$InputDeviceListener"); - ("android.inputmethodservice", "KeyboardView$OnKeyboardActionListener"); - ("android.location", "GpsStatus$Listener"); - ("android.location", "GpsStatus$NmeaListener"); - ("android.location", "LocationListener"); - ("android.media", "AudioManager$OnAudioFocusChangeListener"); - ("android.media", "AudioRecord$OnRecordPositionUpdateListener"); - ("android.media", "JetPlayer$OnJetEventListener"); - ("android.media", "MediaPlayer$OnBufferingUpdateListener"); - ("android.media", "MediaPlayer$OnCompletionListener"); - ("android.media", "MediaPlayer$OnErrorListener"); - ("android.media", "MediaPlayer$OnInfoListener"); - ("android.media", "MediaPlayer$OnPreparedListener"); - ("android.media", "MediaPlayer$OnSeekCompleteListener"); - ("android.media", "MediaPlayer$OnTimedTextListener"); - ("android.media", "MediaPlayer$OnVideoSizeChangedListener"); - ("android.media", "MediaRecorder$OnErrorListener"); - ("android.media", "MediaRecorder$OnInfoListener"); - ("android.media", "MediaScannerConnection$MediaScannerConnectionClient"); - ("android.media", "MediaScannerConnection$OnScanCompletedListener"); - ("android.media", "SoundPool$OnLoadCompleteListener"); - ("android.media.audiofx", "AudioEffect$OnControlStatusChangeListener"); - ("android.media.audiofx", "AudioEffect$OnEnableStatusChangeListener"); - ("android.media.audiofx", "BassBoost$OnParameterChangeListener"); - ("android.media.audiofx", "EnvironmentalReverb$OnParameterChangeListener"); - ("android.media.audiofx", "Equalizer$OnParameterChangeListener"); - ("android.media.audiofx", "PresetReverb$OnParameterChangeListener"); - ("android.media.audiofx", "Virtualizer$OnParameterChangeListener"); - ("android.media.audiofx", "Visualizer$OnDataCaptureListener"); - ("android.media.effect", "EffectUpdateListener"); - ("android.net.nsd", "NsdManager$DiscoveryListener"); - ("android.net.nsd", "NsdManager$RegistrationListener"); - ("android.net.nsd", "NsdManager$ResolveListener"); - ("android.net.sip", "SipRegistrationListener"); - ("android.net.wifi.p2p", "WifiP2pManager$ActionListener"); - ("android.net.wifi.p2p", "WifiP2pManager$ChannelListener"); - ("android.net.wifi.p2p", "WifiP2pManager$ConnectionInfoListener"); - ("android.net.wifi.p2p", "WifiP2pManager$DnsSdServiceResponseListener"); - ("android.net.wifi.p2p", "WifiP2pManager$DnsSdTxtRecordListener"); - ("android.net.wifi.p2p", "WifiP2pManager$GroupInfoListener"); - ("android.net.wifi.p2p", "WifiP2pManager$PeerListListener"); - ("android.net.wifi.p2p", "WifiP2pManager$ServiceResponseListener"); - ("android.net.wifi.p2p", "WifiP2pManager$UpnpServiceResponseListener"); - ("android.os", "CancellationSignal$OnCancelListener"); - ("android.os", "IBinder$DeathRecipient"); - ("android.os", "MessageQueue$IdleHandler"); - ("android.os", "RecoverySystem$ProgressListener"); - ("android.preference", "Preference$OnPreferenceChangeListener"); - ("android.preference", "Preference$OnPreferenceClickListener"); - ("android.preference", "PreferenceFragment$OnPreferenceStartFragmentCallback"); - ("android.preference", "PreferenceManager$OnActivityDestroyListener"); - ("android.preference", "PreferenceManager$OnActivityResultListener"); - ("android.preference", "PreferenceManager$OnActivityStopListener"); - ("android.security", "KeyChainAliasCallback"); - ("android.speech", "RecognitionListener"); - ("android.speech.tts", "TextToSpeech$OnInitListener"); - ("android.speech.tts", "TextToSpeech$OnUtteranceCompletedListener"); - ("android.view", "ActionMode$Callback"); - ("android.view", "ActionProvider$VisibilityListener"); - ("android.view", "GestureDetector$OnDoubleTapListener"); - ("android.view", "GestureDetector$OnGestureListener"); - ("android.view", "InputQueue$Callback"); - ("android.view", "KeyEvent$Callback"); - ("android.view", "MenuItem$OnActionExpandListener"); - ("android.view", "MenuItem$OnMenuItemClickListener"); - ("android.view", "ScaleGestureDetector$OnScaleGestureListener"); - ("android.view", "SurfaceHolder$Callback"); - ("android.view", "SurfaceHolder$Callback2"); - ("android.view", "TextureView$SurfaceTextureListener"); - ("android.view", "View$OnAttachStateChangeListener"); - ("android.view", "View$OnClickListener"); - ("android.view", "View$OnCreateContextMenuListener"); - ("android.view", "View$OnDragListener"); - ("android.view", "View$OnFocusChangeListener"); - ("android.view", "View$OnGenericMotionListener"); - ("android.view", "View$OnHoverListener"); - ("android.view", "View$OnKeyListener"); - ("android.view", "View$OnLayoutChangeListener"); - ("android.view", "View$OnLongClickListener"); - ("android.view", "View$OnSystemUiVisibilityChangeListener"); - ("android.view", "View$OnTouchListener"); - ("android.view", "ViewGroup$OnHierarchyChangeListener"); - ("android.view", "ViewStub$OnInflateListener"); - ("android.view", "ViewTreeObserver$OnDrawListener"); - ("android.view", "ViewTreeObserver$OnGlobalFocusChangeListener"); - ("android.view", "ViewTreeObserver$OnGlobalLayoutListener"); - ("android.view", "ViewTreeObserver$OnPreDrawListener"); - ("android.view", "ViewTreeObserver$OnScrollChangedListener"); - ("android.view", "ViewTreeObserver$OnTouchModeChangeListener"); - ("android.view.accessibility", "AccessibilityManager$AccessibilityStateChangeListener"); - ("android.view.animation", "Animation$AnimationListener"); - ("android.view.inputmethod", "InputMethod$SessionCallback"); - ("android.view.inputmethod", "InputMethodSession$EventCallback"); - ("android.view.textservice", "SpellCheckerSession$SpellCheckerSessionListener"); - ("android.webkit", "DownloadListener"); - ("android.widget", "AbsListView$MultiChoiceModeListener"); - ("android.widget", "AbsListView$OnScrollListener"); - ("android.widget", "AbsListView$RecyclerListener"); - ("android.widget", "AdapterView$OnItemClickListener"); - ("android.widget", "AdapterView$OnItemLongClickListener"); - ("android.widget", "AdapterView$OnItemSelectedListener"); - ("android.widget", "AutoCompleteTextView$OnDismissListener"); - ("android.widget", "CalendarView$OnDateChangeListener"); - ("android.widget", "Chronometer$OnChronometerTickListener"); - ("android.widget", "CompoundButton$OnCheckedChangeListener"); - ("android.widget", "DatePicker$OnDateChangedListener"); - ("android.widget", "ExpandableListView$OnChildClickListener"); - ("android.widget", "ExpandableListView$OnGroupClickListener"); - ("android.widget", "ExpandableListView$OnGroupCollapseListener"); - ("android.widget", "ExpandableListView$OnGroupExpandListener"); - ("android.widget", "Filter$FilterListener"); - ("android.widget", "NumberPicker$OnScrollListener"); - ("android.widget", "NumberPicker$OnValueChangeListener"); - ("android.widget", "NumberPicker$OnDismissListener"); - ("android.widget", "PopupMenu$OnMenuItemClickListener"); - ("android.widget", "PopupWindow$OnDismissListener"); - ("android.widget", "RadioGroup$OnCheckedChangeListener"); - ("android.widget", "RatingBar$OnRatingBarChangeListener"); - ("android.widget", "SearchView$OnCloseListener"); - ("android.widget", "SearchView$OnQueryTextListener"); - ("android.widget", "SearchView$OnSuggestionListener"); - ("android.widget", "SeekBar$OnSeekBarChangeListener"); - ("android.widget", "ShareActionProvider$OnShareTargetSelectedListener"); - ("android.widget", "SlidingDrawer$OnDrawerCloseListener"); - ("android.widget", "SlidingDrawer$OnDrawerOpenListener"); - ("android.widget", "SlidingDrawer$OnDrawerScrollListener"); - ("android.widget", "TabHost$OnTabChangeListener"); - ("android.widget", "TextView$OnEditorActionListener"); - ("android.widget", "TimePicker$OnTimeChangedListener"); - ("android.widget", "ZoomButtonsController$OnZoomListener"); - ] in - IList.fold_left (fun cbSet (pkg, clazz) -> - let qualified_name = Mangled.from_string (pkg ^ "." ^ clazz) in - Mangled.MangledSet.add qualified_name cbSet) Mangled.MangledSet.empty cb_strs - (** return the complete set of superclasses of [typ *) (* TODO (t4644852): factor out subtyping functions into some sort of JavaUtil module *) let get_all_supertypes typ tenv = @@ -297,17 +102,6 @@ let is_fragment typ tenv = is_subtype_package_class typ "android.app" "Fragment" tenv || is_subtype_package_class typ "android.support.v4.app" "Fragment" tenv -(** return true if [class_name] is a known callback class name *) -let is_callback_class_name class_name = Mangled.MangledSet.mem class_name android_callbacks - -(** return true if [typ] is a known callback class *) -let is_callback_class typ tenv = - let supertyps = get_all_supertypes typ tenv in - TypSet.exists (fun typ -> match typ with - | Sil.Tstruct { Sil.csu = Csu.Class _; struct_name = Some classname } -> - is_callback_class_name classname - | _ -> false) supertyps - (** return true if [typ] is a subclass of [lifecycle_typ] *) let typ_is_lifecycle_typ typ lifecycle_typ tenv = let supers = get_all_supertypes typ tenv in @@ -318,50 +112,6 @@ let is_android_lib_class class_name = let class_str = Typename.name class_name in string_is_prefix "android" class_str || string_is_prefix "com.android" class_str -(** returns an option containing the var name and type of a callback registered by [procname], - None if no callback is registered *) -let get_callback_registered_by (pname_java : Procname.java) args tenv = - (* TODO (t4565077): this check should be replaced with a membership check in a hardcoded list of - * Android callback registration methods *) - (* for now, we assume a method is a callback registration method if it is a setter and has a - * callback class as a non - receiver argument *) - let is_callback_register_like = - let has_non_this_callback_arg args = IList.length args > 1 in - let has_registery_name () = - PatternMatch.is_setter pname_java || - is_known_callback_register_method (Procname.java_get_method pname_java) in - has_registery_name () && - has_non_this_callback_arg args in - let is_ptr_to_callback_class typ tenv = match typ with - | Sil.Tptr (typ, Sil.Pk_pointer) -> is_callback_class typ tenv - | _ -> false in - if is_callback_register_like then - (* we don't want to check if the receiver is a callback class; it's one of the method arguments - * that's being registered as a callback *) - let get_non_this_args args = IList.tl args in - try - Some (IList.find (fun (_, typ) -> is_ptr_to_callback_class typ tenv) (get_non_this_args args)) - with Not_found -> None - else None - -(** return a list of typ's corresponding to callback classes registered by [procdesc] *) -let get_callbacks_registered_by_proc procdesc tenv = - let collect_callback_typs callback_typs _ instr = match instr with - | Sil.Call ([], Sil.Const (Sil.Cfun callee), args, _, _) -> - begin - match callee with - | Procname.Java callee_java -> - begin - match get_callback_registered_by callee_java args tenv with - | Some (_, callback_typ) -> callback_typ :: callback_typs - | None -> callback_typs - end - | _ -> - callback_typs - end - | _ -> callback_typs in - Cfg.Procdesc.fold_instrs collect_callback_typs [] procdesc - (** given an Android framework type mangled string [lifecycle_typ] (e.g., android.app.Activity) and a list of method names [lifecycle_procs_strs], get the appropriate typ and procnames *) let get_lifecycle_for_framework_typ_opt lifecycle_typ lifecycle_proc_strs tenv = diff --git a/infer/src/harness/androidFramework.mli b/infer/src/harness/androidFramework.mli index 2e197a182..b8d7df0f5 100644 --- a/infer/src/harness/androidFramework.mli +++ b/infer/src/harness/androidFramework.mli @@ -17,9 +17,6 @@ val get_lifecycles : (string * string * string list) list (** return true if [typ] is a subclass of [lifecycle_typ] *) val typ_is_lifecycle_typ : Sil.typ -> Sil.typ -> Tenv.t -> bool -(** return true if [typ] is a known callback class, false otherwise *) -val is_callback_class : Sil.typ -> Tenv.t -> bool - (** return true if [typ] <: android.content.Context *) val is_context : Sil.typ -> Tenv.t -> bool @@ -37,14 +34,6 @@ val is_fragment : Sil.typ -> Tenv.t -> bool (** return true if [procname] is a special lifecycle cleanup method *) val is_destroy_method : Procname.t -> bool -(** returns an option containing the var name and type of a callback registered by [procname], - None if no callback is registered *) -val get_callback_registered_by : - Procname.java -> (Sil.exp * Sil.typ) list -> Tenv.t -> (Sil.exp * Sil.typ) option - -(** return a list of typ's corresponding to callback classes registered by [procdesc] *) -val get_callbacks_registered_by_proc : Cfg.Procdesc.t -> Tenv.t -> Sil.typ list - (** given an Android framework type mangled string [lifecycle_typ] (e.g., android.app.Activity) and a list of method names [lifecycle_procs_strs], get the appropriate typ and procnames *) val get_lifecycle_for_framework_typ_opt :