From 354b46f8caae4c41acc87fccb42c8c5288afb7b6 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 17 Nov 2017 21:08:03 -0800 Subject: [PATCH] [infer][nullable checker] no report for objects created by URLWithString: Reviewed By: sblackshear Differential Revision: D6354108 fbshipit-source-id: 16e3fe0 --- infer/src/checkers/NullabilityCheck.ml | 8 ++++++++ infer/tests/codetoanalyze/objc/checkers/Nullable.m | 5 +++++ infer/tests/codetoanalyze/objc/checkers/issues.exp | 2 ++ 3 files changed, 15 insertions(+) diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index b4f296a55..940eacee8 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -29,6 +29,12 @@ module TransferFunctions (CFG : ProcCfg.S) = struct (Specs.proc_resolve_attributes callee_pname) + let is_blacklisted callee_pname = + let blacklist = ["URLWithString:"] + and simplified_callee_pname = Typ.Procname.to_simplified_string callee_pname in + List.exists ~f:(String.equal simplified_callee_pname) blacklist + + let report_nullable_dereference ap call_sites {ProcData.pdesc; extras} loc = let pname = Procdesc.get_proc_name pdesc in let annotation = Localise.nullable_annotation_name pname in @@ -162,6 +168,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | Call (_, Direct callee_pname, (HilExp.AccessPath receiver) :: _, _, _) when Models.is_check_not_null callee_pname -> assume_pnames_notnull receiver astate + | Call (_, Direct callee_pname, _, _, _) when is_blacklisted callee_pname -> + astate | Call (Some ret_var, Direct callee_pname, _, _, loc) when Annotations.pname_has_return_annot callee_pname ~attrs_of_pname:Specs.proc_resolve_attributes Annotations.ia_is_nullable -> diff --git a/infer/tests/codetoanalyze/objc/checkers/Nullable.m b/infer/tests/codetoanalyze/objc/checkers/Nullable.m index 83be1ce47..1432c0226 100644 --- a/infer/tests/codetoanalyze/objc/checkers/Nullable.m +++ b/infer/tests/codetoanalyze/objc/checkers/Nullable.m @@ -140,4 +140,9 @@ int* __nullable returnsNull(); return array; } +- (NSArray*)URLWithStringOkay { + NSURL* url = [NSURL URLWithString:@"some/url/string"]; + NSArray* array = @[ url ]; +} + @end diff --git a/infer/tests/codetoanalyze/objc/checkers/issues.exp b/infer/tests/codetoanalyze/objc/checkers/issues.exp index 657d10126..fa65d2635 100644 --- a/infer/tests/codetoanalyze/objc/checkers/issues.exp +++ b/infer/tests/codetoanalyze/objc/checkers/issues.exp @@ -1,5 +1,7 @@ codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here] codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 2, NULL_DEREFERENCE, [start of procedure FP_dereferenceNonnullFieldAfterTestForNullOkay,Condition is true] +codetoanalyze/objc/checkers/Nullable.m, T_URLWithStringOkay, 2, DEAD_STORE, [Write of unused value] +codetoanalyze/objc/checkers/Nullable.m, T_URLWithStringOkay, 2, NULL_DEREFERENCE, [start of procedure URLWithStringOkay,Skipping URLWithString:: function or method not found] codetoanalyze/objc/checkers/Nullable.m, T_assignNonnullFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is assigned null here] codetoanalyze/objc/checkers/Nullable.m, T_assignUnnanotatedFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is assigned null here] codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFieldBad, 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableFieldBad]