diff --git a/infer/documentation/issues/VECTOR_INVALIDATION.md b/infer/documentation/issues/VECTOR_INVALIDATION.md index 3c08204d6d..cf2048d6ba 100644 --- a/infer/documentation/issues/VECTOR_INVALIDATION.md +++ b/infer/documentation/issues/VECTOR_INVALIDATION.md @@ -1,5 +1,6 @@ -An address pointing into a C++ `std::vector` might have become -invalid. This can happen when an address is taken into a vector, then +An address pointing into a C++ `std::vector`, or into another container +of the standard library (see below), might have become invalid. This +can happen when an address is taken into a vector, then the vector is mutated in a way that might invalidate the address, for example by adding elements to the vector, which might trigger a re-allocation of the entire vector contents (thereby invalidating the @@ -17,3 +18,37 @@ void deref_vector_element_after_push_back_bad(std::vector& vec) { std::cout << *y << "\n"; // bad: y might be invalid } ``` + +The same applies to the buffer of a `std::basic_string`: the pointer +returned by `data()` or `c_str()`, an iterator returned by `begin()`, +or the pointer returned by `data()` of a `std::string_view` of the +string, might become invalid after a call to a mutating member +function such as `append()`, `clear()`, `push_back()`, `operator+=`, +`operator=` or `reserve()`, as the standard allows. Unlike for +`std::vector`, this is reported even after a call to `reserve()`. + +```cpp +char deref_c_str_after_append_bad(std::string& s) { + const char* p = s.c_str(); + s.append(1000, 'x'); // may re-allocate the buffer + return *p; // bad: p might be invalid +} +``` + +This issue is also reported for other containers of the standard library +(`std::deque`, `std::list`, `std::map`, `std::set`, `std::unordered_map`, +etc.) when an iterator or a reference to an element is used after an operation +that invalidates it, for instance after the element was removed with `erase()` +or `clear()`, or after an insertion into a `std::deque`, which invalidates all +its iterators. Dereferencing the `end()` iterator of a container is reported +too. + +```cpp +void erase_in_loop_bad(std::map& map) { + for (auto it = map.begin(); it != map.end(); ++it) { + if (it->second == 0) { + map.erase(it); // bad: `it` is invalid after this, so `++it` is too + } + } +} +``` diff --git a/infer/src/absint/ProcnameDispatcher.ml b/infer/src/absint/ProcnameDispatcher.ml index 86989a85ab..99706a7a92 100644 --- a/infer/src/absint/ProcnameDispatcher.ml +++ b/infer/src/absint/ProcnameDispatcher.ml @@ -168,7 +168,9 @@ let name_cons : fun m name -> let {on_templated_name} = m in let match_fuzzy_name = - let fuzzy_name_regexp = name |> Str.quote |> Printf.sprintf "^%s\\(<.+>\\)?$" |> Str.regexp in + (* the frontend appends the template arguments of function template instantiations to their + names, e.g. [foo], or [foo<>] when they are all empty parameter packs *) + let fuzzy_name_regexp = name |> Str.quote |> Printf.sprintf "^%s\\(<.*>\\)?$" |> Str.regexp in fun s -> Str.string_match fuzzy_name_regexp s 0 in let on_qual_name context f qual_name = diff --git a/infer/src/pulse/PulseAbductiveDomain.ml b/infer/src/pulse/PulseAbductiveDomain.ml index 7c66912435..5e32318f59 100644 --- a/infer/src/pulse/PulseAbductiveDomain.ml +++ b/infer/src/pulse/PulseAbductiveDomain.ml @@ -2830,6 +2830,47 @@ module AddressAttributes = struct SafeAttributes.is_hack_constinit_called (CanonValue.canon' astate v) astate end +let is_read_from_pre_cell astate (v, hist) = + (* the result of an unknown call is a fresh value, but its history carries the cell ids of the + actuals *) + let rec is_unknown_call_result (hist : ValueHistory.t) = + match hist with + | UnknownCall _ -> + true + | Sequence (Call {in_call; _}, hist) -> + is_unknown_call_result in_call || is_unknown_call_result hist + | Sequence (_, hist) | FromCellIds (_, hist) -> + is_unknown_call_result hist + | BinaryOp (_, hist1, hist2) -> + is_unknown_call_result hist1 || is_unknown_call_result hist2 + | Multiplex hists -> + List.exists hists ~f:is_unknown_call_result + | Epoch -> + false + in + let v = CanonValue.canon' astate v in + match ValueHistory.get_cell_ids hist with + | Some cell_ids -> + BaseMemory.exists + (fun _ edges -> + BaseMemory.Edges.exists edges ~f:(fun (_, (dest, dest_hist)) -> + Option.exists (ValueHistory.get_cell_id_exn dest_hist) ~f:(fun cell_id -> + ValueHistory.CellId.Set.mem cell_id cell_ids ) + && CanonValue.equal (CanonValue.canon astate dest) v ) ) + (astate.pre :> base_domain).heap + && not (is_unknown_call_result hist) + | None -> ( + (* the initial values of object parameters have no cell id, see [add_static_types] *) + match ValueHistory.get_first_event hist with + | Some (ValueHistory.FormalDeclared (pvar, _, _) | Capture {captured_as= pvar; _}) -> + SafeStack.find_opt `Pre (Var.of_pvar pvar) astate + |> Option.bind ~f:(fun vo -> + SafeMemory.find_edge_opt `Pre (ValueOrigin.value vo) Dereference astate ) + |> Option.exists ~f:(fun (formal_value, _) -> CanonValue.equal formal_value v) + | _ -> + false ) + + (* [recurse] is here to enforce that we can only ever make one recursive call when calling into this function. That's what the code should ensure already as we should only ever need one recursive call (namely when we are changing the history of a logical var: we should also update the history diff --git a/infer/src/pulse/PulseAbductiveDomain.mli b/infer/src/pulse/PulseAbductiveDomain.mli index 819ddec717..cf51aa3321 100644 --- a/infer/src/pulse/PulseAbductiveDomain.mli +++ b/infer/src/pulse/PulseAbductiveDomain.mli @@ -198,6 +198,9 @@ module Memory : sig [x|->z * y |->z'], with [z'] a fresh abstract value. This is used for abstraction. *) end +val is_read_from_pre_cell : t -> AbstractValue.t * ValueHistory.t -> bool +(** whether the history of the value names a cell of the pre-condition that holds this value *) + (** Safe version of {!PulseBaseAddressAttributes} *) module AddressAttributes : sig val abduce_one : AbstractValue.t -> Attribute.t -> t -> t diff --git a/infer/src/pulse/PulseCallOperations.ml b/infer/src/pulse/PulseCallOperations.ml index 17110cd4d9..6aebdcec5e 100644 --- a/infer/src/pulse/PulseCallOperations.ml +++ b/infer/src/pulse/PulseCallOperations.ml @@ -69,6 +69,9 @@ let matches_iter = [ "std::__detail::_Node_iterator" ; "std::__wrap_iter" ; "std::_Rb_tree_iterator" + ; "std::back_insert_iterator" + ; "std::front_insert_iterator" + ; "std::insert_iterator" ; "__gnu_cxx::__normal_iterator" ] diff --git a/infer/src/pulse/PulseDiagnostic.ml b/infer/src/pulse/PulseDiagnostic.ml index a435b427a3..d4c9822613 100644 --- a/infer/src/pulse/PulseDiagnostic.ml +++ b/infer/src/pulse/PulseDiagnostic.ml @@ -1077,7 +1077,9 @@ let invalidation_titles (invalidation : Invalidation.t) = | GoneOutOfScope _ | OptionalEmpty | StdVector _ - | CppMap _ -> + | StdString _ + | CppMap _ + | StdContainer _ -> ( "invalidation part of the trace starts here" , "use-after-lifetime part of the trace starts here" ) diff --git a/infer/src/pulse/PulseInvalidation.ml b/infer/src/pulse/PulseInvalidation.ml index 8256e02b68..16d7e1c9b2 100644 --- a/infer/src/pulse/PulseInvalidation.ml +++ b/infer/src/pulse/PulseInvalidation.ml @@ -12,9 +12,11 @@ type std_vector_function = | Clear | Emplace | EmplaceBack + | Erase | Insert | PushBack | Reserve + | Resize | ShrinkToFit [@@deriving compare, equal, yojson_of] @@ -27,16 +29,151 @@ let pp_std_vector_function f = function F.fprintf f "std::vector::emplace" | EmplaceBack -> F.fprintf f "std::vector::emplace_back" + | Erase -> + F.fprintf f "std::vector::erase" | Insert -> F.fprintf f "std::vector::insert" | PushBack -> F.fprintf f "std::vector::push_back" | Reserve -> F.fprintf f "std::vector::reserve" + | Resize -> + F.fprintf f "std::vector::resize" | ShrinkToFit -> F.fprintf f "std::vector::shrink_to_fit" +type std_string_function = + | Append + | Assign + | Clear + | Erase + | Insert + | OperatorAssign + | OperatorPlusAssign + | PopBack + | PushBack + | Replace + | Reserve + | Resize + | ShrinkToFit +[@@deriving compare, equal, yojson_of] + +let all_std_string_functions : std_string_function list = + [ Append + ; Assign + ; Clear + ; Erase + ; Insert + ; OperatorAssign + ; OperatorPlusAssign + ; PopBack + ; PushBack + ; Replace + ; Reserve + ; Resize + ; ShrinkToFit ] + + +let std_string_method_name = function + | Append -> + "append" + | Assign -> + "assign" + | Clear -> + "clear" + | Erase -> + "erase" + | Insert -> + "insert" + | OperatorAssign -> + "operator=" + | OperatorPlusAssign -> + "operator+=" + | PopBack -> + "pop_back" + | PushBack -> + "push_back" + | Replace -> + "replace" + | Reserve -> + "reserve" + | Resize -> + "resize" + | ShrinkToFit -> + "shrink_to_fit" + + +let pp_std_string_function f std_string_f = + F.fprintf f "std::basic_string::%s" (std_string_method_name std_string_f) + + +type std_container = + | Deque + | List + | Map + | Multimap + | Multiset + | Set + | UnorderedMap + | UnorderedMultimap + | UnorderedMultiset + | UnorderedSet +[@@deriving compare, equal, yojson_of] + +type std_container_function = + | Clear + | Emplace + | EmplaceBack + | EmplaceFront + | Erase + | Insert + | PushBack + | PushFront +[@@deriving compare, equal, yojson_of] + +let pp_std_container f = function + | Deque -> + F.fprintf f "std::deque" + | List -> + F.fprintf f "std::list" + | Map -> + F.fprintf f "std::map" + | Multimap -> + F.fprintf f "std::multimap" + | Multiset -> + F.fprintf f "std::multiset" + | Set -> + F.fprintf f "std::set" + | UnorderedMap -> + F.fprintf f "std::unordered_map" + | UnorderedMultimap -> + F.fprintf f "std::unordered_multimap" + | UnorderedMultiset -> + F.fprintf f "std::unordered_multiset" + | UnorderedSet -> + F.fprintf f "std::unordered_set" + + +let pp_std_container_function f = function + | Clear -> + F.fprintf f "clear" + | Emplace -> + F.fprintf f "emplace" + | EmplaceBack -> + F.fprintf f "emplace_back" + | EmplaceFront -> + F.fprintf f "emplace_front" + | Erase -> + F.fprintf f "erase" + | Insert -> + F.fprintf f "insert" + | PushBack -> + F.fprintf f "push_back" + | PushFront -> + F.fprintf f "push_front" + + type map_type = FollyF14Value | FollyF14Vector | FollyF14Fast [@@deriving compare, equal, yojson_of] @@ -99,7 +236,9 @@ type t = | GoneOutOfScope of Pvar.t * Typ.t | OptionalEmpty | StdVector of std_vector_function + | StdString of std_string_function | CppMap of map_type * map_function + | StdContainer of std_container * std_container_function [@@deriving compare, equal, yojson_of, variants] let is_same_type invalidation1 invalidation2 = @@ -160,7 +299,7 @@ let issue_type_of_cause ~latent invalidation must_be_valid_reason = IssueType.use_after_lifetime ~latent | OptionalEmpty -> IssueType.optional_empty_access ~latent - | StdVector _ -> + | StdVector _ | StdString _ | StdContainer _ -> IssueType.vector_invalidation ~latent | CppMap _ -> IssueType.pulse_reference_stability @@ -195,8 +334,13 @@ let describe f cause = F.pp_print_string f "is assigned an empty value" | StdVector std_vector_f -> F.fprintf f "was potentially invalidated by `%a`" pp_std_vector_function std_vector_f + | StdString std_string_f -> + F.fprintf f "was potentially invalidated by `%a`" pp_std_string_function std_string_f | CppMap (map_t, map_f) -> F.fprintf f "was potentially invalidated by `%a::%a`" pp_map_type map_t pp_map_function map_f + | StdContainer (container, container_f) -> + F.fprintf f "was invalidated by `%a::%a`" pp_std_container container pp_std_container_function + container_f let suggest cause = @@ -227,5 +371,9 @@ let pp f invalidation = F.fprintf f "FClose(%a)" describe invalidation | StdVector _ -> F.fprintf f "StdVector(%a)" describe invalidation + | StdString _ -> + F.fprintf f "StdString(%a)" describe invalidation | CppMap _ -> F.fprintf f "CppMap(%a)" describe invalidation + | StdContainer _ -> + F.fprintf f "StdContainer(%a)" describe invalidation diff --git a/infer/src/pulse/PulseInvalidation.mli b/infer/src/pulse/PulseInvalidation.mli index 4a0bb87910..cf05ee46cf 100644 --- a/infer/src/pulse/PulseInvalidation.mli +++ b/infer/src/pulse/PulseInvalidation.mli @@ -13,14 +13,64 @@ type std_vector_function = | Clear | Emplace | EmplaceBack + | Erase | Insert | PushBack | Reserve + | Resize | ShrinkToFit [@@deriving compare, equal, yojson_of] val pp_std_vector_function : F.formatter -> std_vector_function -> unit +type std_string_function = + | Append + | Assign + | Clear + | Erase + | Insert + | OperatorAssign + | OperatorPlusAssign + | PopBack + | PushBack + | Replace + | Reserve + | Resize + | ShrinkToFit +[@@deriving compare, equal, yojson_of] + +val all_std_string_functions : std_string_function list + +val std_string_method_name : std_string_function -> string +(** name of the [std::basic_string] member function, e.g. ["push_back"] *) + +val pp_std_string_function : F.formatter -> std_string_function -> unit + +(** [std::deque] and the node-based containers of the C++ standard library *) +type std_container = + | Deque + | List + | Map + | Multimap + | Multiset + | Set + | UnorderedMap + | UnorderedMultimap + | UnorderedMultiset + | UnorderedSet +[@@deriving compare, equal, yojson_of] + +type std_container_function = + | Clear + | Emplace + | EmplaceBack + | EmplaceFront + | Erase + | Insert + | PushBack + | PushFront +[@@deriving compare, equal, yojson_of] + type map_type = FollyF14Value | FollyF14Vector | FollyF14Fast [@@deriving compare, equal, yojson_of] @@ -53,7 +103,9 @@ type t = | GoneOutOfScope of Pvar.t * Typ.t | OptionalEmpty | StdVector of std_vector_function + | StdString of std_string_function | CppMap of map_type * map_function + | StdContainer of std_container * std_container_function [@@deriving compare, equal, yojson_of] val pp : F.formatter -> t -> unit diff --git a/infer/src/pulse/PulseModels.ml b/infer/src/pulse/PulseModels.ml index a7f80cc669..1850f73952 100644 --- a/infer/src/pulse/PulseModels.ml +++ b/infer/src/pulse/PulseModels.ml @@ -15,10 +15,11 @@ module ProcNameDispatcher = struct ( FbPulseModels.matchers @ PulseModelsCSharp.matchers @ PulseModelsObjC.transfer_ownership_matchers @ PulseModelsCpp.abort_matchers @ PulseModelsAndroid.matchers @ PulseModelsC.matchers @ PulseModelsCpp.matchers - @ PulseModelsErlang.matchers @ PulseModelsGenericArrayBackedCollection.matchers - @ PulseModelsHack.matchers @ PulseModelsJava.matchers @ PulseModelsObjC.matchers - @ PulseModelsOptional.matchers @ PulseModelsSmartPointers.matchers @ PulseModelsLocks.matchers - @ PulseModelsRust.matchers @ Basic.matchers ) + @ PulseModelsStdContainers.matchers @ PulseModelsErlang.matchers + @ PulseModelsGenericArrayBackedCollection.matchers @ PulseModelsHack.matchers + @ PulseModelsJava.matchers @ PulseModelsObjC.matchers @ PulseModelsOptional.matchers + @ PulseModelsSmartPointers.matchers @ PulseModelsLocks.matchers @ PulseModelsRust.matchers + @ Basic.matchers ) end let dispatch tenv proc_name args = diff --git a/infer/src/pulse/PulseModelsCpp.ml b/infer/src/pulse/PulseModelsCpp.ml index 984f76c2d1..94d448f5e3 100644 --- a/infer/src/pulse/PulseModelsCpp.ml +++ b/infer/src/pulse/PulseModelsCpp.ml @@ -6,6 +6,7 @@ *) open! IStd +module IRAttributes = Attributes module L = Logging open PulseBasicInterface open PulseDomainInterface @@ -280,10 +281,8 @@ module BasicString = struct constructor_from_constant_dsl this_hist init_hist - let copy_constructor ~desc (this, hist) src_hist : model = + let copy_constructor_dsl (this, hist) src_hist : unit PulseModelsDSL.model_monad = let open PulseModelsDSL.Syntax in - start_named_model desc - @@ fun () -> let* this_hist = add_model_call hist in let* src_string = load_access src_hist (FieldAccess ModeledField.internal_string) in let* src_length = access Read src_hist (FieldAccess ModeledField.string_length) in @@ -291,24 +290,32 @@ module BasicString = struct @@> write_field ~ref:(this, this_hist) ModeledField.string_length src_length - let constructor_rev ~desc init this : model = copy_constructor ~desc this init + let copy_constructor ~desc this_hist src_hist : model = + let open PulseModelsDSL.Syntax in + start_named_model desc @@ fun () -> copy_constructor_dsl this_hist src_hist - let data this_hist ~desc : model = + + let data ((this, hist) as this_hist) ~desc : model = let open PulseModelsDSL.Syntax in start_named_model desc @@ fun () -> let* this_string, this_string_hist = access Read this_hist (FieldAccess ModeledField.internal_string) in - let* hist = add_model_call this_string_hist in - assign_ret (this_string, hist) + let* ret_hist = add_model_call this_string_hist in + exec_command + (AbductiveDomain.AddressAttributes.add_one this_string + (PropagateTaintFrom (InternalModel, [{v= this; history= hist}])) ) + @@> assign_ret (this_string, ret_hist) let iterator_common ((this, hist) as this_hist) ((iter, _) as iter_hist) : (PulseModelsDSL.aval * PulseModelsDSL.aval) PulseModelsDSL.model_monad = let open PulseModelsDSL.Syntax in let* backing_ptr = access Read iter_hist (FieldAccess GenericArrayBackedCollection.field) in - let* internal_string = load_access this_hist (FieldAccess ModeledField.internal_string) in + let* internal_string = + load_access ~deref:false this_hist (FieldAccess ModeledField.internal_string) + in exec_command (AbductiveDomain.AddressAttributes.add_one iter (PropagateTaintFrom (InternalModel, [{v= this; history= hist}])) ) @@ -360,6 +367,41 @@ module BasicString = struct location CppDelete (string_addr, string_hist) astate ) ) + (** Mutating member functions may reallocate the buffer, so the buffer returned by [data()] or + [c_str()] before the call is invalidated and replaced by a fresh one. The call is otherwise + treated as unknown, also for taint (see [PulseTaintOperations]), except that the overloads + returning [basic_string&] return the receiver. *) + let mutator string_f ({FuncArg.arg_payload= this} as this_arg) args : model_no_non_disj = + fun {path; callee_procname; analysis_data= {tenv}; location; ret} astate -> + let internal_string = PulseOperations.ModeledField.internal_string in + let new_buffer = + let desc = Format.asprintf "%a()" Invalidation.pp_std_string_function string_f in + (AbstractValue.mk_fresh (), Hist.single_call path location desc) + in + let<*> astate = + PulseOperations.invalidate_access path location (StdString string_f) this + (FieldAccess internal_string) astate + |> PulseOperations.write_field path location ~ref:this internal_string ~obj:new_buffer + in + let actuals = + List.map (this_arg :: args) ~f:(fun {FuncArg.arg_payload; typ} -> (arg_payload, typ)) + in + let attrs_opt = IRAttributes.load callee_procname in + let formals_opt = Option.map attrs_opt ~f:ProcAttributes.get_pvar_formals in + let returns_this = + match attrs_opt with + | Some {ProcAttributes.ret_type= {desc= Tptr ({desc= Tstruct ret_class}, _)}} -> + Option.exists (Procname.get_class_type_name callee_procname) ~f:(Typ.Name.equal ret_class) + | _ -> + false + in + let<++> astate = + PulseCallOperations.unknown_call tenv path location (SkippedKnownCall callee_procname) + (Some callee_procname) ~ret ~actuals ~formals_opt astate + in + if returns_this then PulseOperations.write_id (fst ret) this astate else astate + + let empty this_hist : model = let open PulseModelsDSL.Syntax in start_named_model "std::basic_string::empty()" @@ -395,6 +437,78 @@ module BasicString = struct SatUnsat.to_list astate_zero_idx @ astate_non_zero_idx end +(** A [std::basic_string_view] keeps the string value and length of what it views like [BasicString] + does, and in [data_field] the pointer returned by [data()]: the viewed [char*] or the buffer of + the viewed [std::basic_string]. Copies of a view share that pointer, so they see the + invalidation of the viewed buffer. *) +module BasicStringView = struct + let data_field = Fieldname.make PulseOperations.pulse_model_type "__infer_model_string_view_data" + + let store_data this_hist (data, data_hist) : unit PulseModelsDSL.model_monad = + let open PulseModelsDSL.Syntax in + let* data_hist = add_model_call data_hist in + store_field ~ref:this_hist data_field (data, data_hist) + + + let constructor_from_char_ptr ~desc this_hist ptr_hist : model = + let open PulseModelsDSL.Syntax in + start_named_model desc + @@ fun () -> + BasicString.constructor_from_constant_dsl this_hist ptr_hist @@> store_data this_hist ptr_hist + + + (** [basic_string_view(const char* s, size_t count)] and the C++20 iterator-pair constructor *) + let constructor_from_char_ptr_and_size ~desc ((this, hist) as this_hist) ptr_hist + (size_arg : PulseModelsDSL.aval FuncArg.t) : model = + let open PulseModelsDSL.Syntax in + start_named_model desc + @@ fun () -> + store_data this_hist ptr_hist + @@> + if Typ.is_int size_arg.typ then + let* hist = add_model_call hist in + write_field ~ref:(this, hist) ModeledField.string_length size_arg.arg_payload + else ret () + + + let copy_dsl this_hist src_hist : unit PulseModelsDSL.model_monad = + let open PulseModelsDSL.Syntax in + BasicString.copy_constructor_dsl this_hist src_hist + @@> let* data = load_access src_hist (FieldAccess data_field) in + store_data this_hist data + + + let copy_constructor ~desc this_hist src_hist : model = + let open PulseModelsDSL.Syntax in + start_named_model desc @@ fun () -> copy_dsl this_hist src_hist + + + let assign ~desc this_hist src_hist : model = + let open PulseModelsDSL.Syntax in + start_named_model desc @@ fun () -> copy_dsl this_hist src_hist @@> assign_ret this_hist + + + (** [std::basic_string::operator basic_string_view()] *) + let of_string ~desc string_hist this_hist : model = + let open PulseModelsDSL.Syntax in + start_named_model desc + @@ fun () -> + BasicString.copy_constructor_dsl this_hist string_hist + @@> let* buffer = + load_access ~deref:false string_hist (FieldAccess ModeledField.internal_string) + in + store_data this_hist buffer + + + let data this_hist ~desc : model = + let open PulseModelsDSL.Syntax in + start_named_model desc + @@ fun () -> + let* data, data_hist = load_access this_hist (FieldAccess data_field) in + let* hist = add_model_call data_hist in + assign_ret (data, hist) +end + module Function = struct let operator_call ~deref_lambda_ptr FuncArg.{arg_payload= lambda_ptr_hist; typ} actuals : model = fun {path; analysis_data; location; ret= (ret_id, _) as ret} astate non_disj -> @@ -538,6 +652,38 @@ module Vector = struct astate + let havoc_size path location vector ~desc astate = + GenericArrayBackedCollection.assign_size path location vector + (AbstractValue.mk_fresh (), ValueHistory.epoch) + ~desc astate + + + let invalidate_references_unknown_size vector_f vector : model_no_non_disj = + fun ({path; location} as model_data) astate -> + let desc = Format.asprintf "%a()" Invalidation.pp_std_vector_function vector_f in + let<*> astate = havoc_size path location vector ~desc astate in + invalidate_references vector_f vector model_data astate + + + let invalidate_references_one_more vector_f vector : model_no_non_disj = + fun ({path; location} as model_data) astate -> + let desc = Format.asprintf "%a()" Invalidation.pp_std_vector_function vector_f in + let<**> astate = GenericArrayBackedCollection.increase_size path location vector ~desc astate in + invalidate_references vector_f vector model_data astate + + + let assign_count vector FuncArg.{arg_payload= count; typ} : model_no_non_disj = + fun ({path; location} as model_data) astate -> + (* [assign(first, last)] has the same arity *) + if Typ.is_int typ then + let<*> astate = + GenericArrayBackedCollection.assign_size path location vector count + ~desc:"std::vector::assign()" astate + in + invalidate_references Assign vector model_data astate + else invalidate_references_unknown_size Assign vector model_data astate + + let invalidate_references_with_ret vector_f vector : model_no_non_disj = fun ({ret= ret_id, _} as model_data) astate -> PulseOperations.write_id ret_id vector astate @@ -553,33 +699,56 @@ module Vector = struct PulseOperations.write_id (fst ret) (addr, Hist.add_event event hist) astate - let vector_begin vector iter : model_no_non_disj = + let last_index path location vector astate = + let=* astate, (size, _) = + GenericArrayBackedCollection.to_internal_size_deref path Read location vector astate + in + PulseArithmetic.eval_binop (AbstractValue.mk_fresh ()) (MinusA None) (AbstractValueOperand size) + (ConstOperand (Cint IntLit.one)) astate + + + (* the return type is checked because [std::vector] can return its elements by value *) + let front ~desc vector : model_no_non_disj = + fun ({ret= _, ret_typ} as model_data) astate -> + if Typ.is_pointer ret_typ then + let index_zero = AbstractValue.mk_fresh () in + let<**> astate = PulseArithmetic.and_eq_int index_zero IntLit.zero astate in + at ~desc vector (index_zero, ValueHistory.epoch) model_data astate + else Basic.nondet ~desc model_data astate + + + let back ~desc vector : model_no_non_disj = + fun ({path; location; ret= _, ret_typ} as model_data) astate -> + if Typ.is_pointer ret_typ then + let<**> astate, last = last_index path location vector astate in + at ~desc vector (last, ValueHistory.epoch) model_data astate + else Basic.nondet ~desc model_data astate + + + let data ~desc vector : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<+> astate, (arr_addr, arr_hist) = + GenericArrayBackedCollection.eval path Read location vector astate + in + PulseOperations.write_id ret_id (arr_addr, Hist.add_event event arr_hist) astate + + + let vector_begin ~desc vector iter : model_no_non_disj = fun {path; location} astate -> - let event = Hist.call_event path location "std::vector::begin()" in - let pointer_hist = Hist.add_event event (snd iter) in - let pointer_val = (AbstractValue.mk_fresh (), pointer_hist) in + let event = Hist.call_event path location desc in let index_zero = AbstractValue.mk_fresh () in let<**> astate = PulseArithmetic.and_eq_int index_zero IntLit.zero astate in - let<*> astate, (arr_addr, _arr_hist) = - GenericArrayBackedCollection.eval path Read location vector astate - in - let<*> astate, elem_at_zero = - GenericArrayBackedCollection.eval_element path location (arr_addr, pointer_hist) index_zero - astate - in let<+> astate = - PulseOperations.write_deref_field path location ~ref:iter GenericArrayBackedCollection.field - ~obj:(arr_addr, pointer_hist) astate - >>= PulseOperations.write_field path location ~ref:iter - GenericArrayBackedCollection.Iterator.internal_pointer ~obj:pointer_val - >>= PulseOperations.write_deref path location ~ref:pointer_val ~obj:elem_at_zero + GenericArrayBackedCollection.Iterator.point_into path location event ~collection:vector ~iter + ~index:index_zero astate in astate - let vector_end vector iter : model_no_non_disj = + let vector_end ~desc vector iter : model_no_non_disj = fun {path; location} astate -> - let event = Hist.call_event path location "std::vector::end()" in + let event = Hist.call_event path location desc in let<*> astate, (arr_addr, _) = GenericArrayBackedCollection.eval path Read location vector astate in @@ -615,23 +784,26 @@ module Vector = struct astate + let reallocate_unless_reserved path location vector vector_f ~desc astate = + if AddressAttributes.is_std_vector_reserved (fst vector) astate then + (* assume that growing the vector is ok after one called [reserve] on the same vector (a + perfect analysis would also make sure we don't exceed the reserved size) *) + Ok astate + else + match vector_f with + | None -> + Ok astate + | Some vector_f -> + (* simulate a re-allocation of the underlying array every time the vector grows *) + reallocate_internal_array path + (Hist.single_call path location desc) + vector vector_f location astate + + let push_back_common vector ~vector_f ~desc : model_no_non_disj = fun {path; location; ret= ret_id, _} astate -> let<**> astate = GenericArrayBackedCollection.increase_size path location vector ~desc astate in - let<+> astate = - let hist = Hist.single_call path location desc in - if AddressAttributes.is_std_vector_reserved (fst vector) astate then - (* assume that any call to [push_back] is ok after one called [reserve] on the same vector - (a perfect analysis would also make sure we don't exceed the reserved size) *) - Ok astate - else - match vector_f with - | None -> - Ok astate - | Some vector_f -> - (* simulate a re-allocation of the underlying array every time an element is added *) - reallocate_internal_array path hist vector vector_f location astate - in + let<+> astate = reallocate_unless_reserved path location vector vector_f ~desc astate in PulseOperations.write_id ret_id (fst vector, Hist.add_call path location desc (snd vector)) astate @@ -640,6 +812,62 @@ module Vector = struct let push_back_cpp vector ~vector_f ~desc = push_back_common vector ~vector_f:(Some vector_f) ~desc let push_back vector ~desc = push_back_common vector ~vector_f:None ~desc + + let emplace_back vector ~desc : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let<**> astate = GenericArrayBackedCollection.increase_size path location vector ~desc astate in + let<*> astate = + reallocate_unless_reserved path location vector (Some EmplaceBack) ~desc astate + in + (* since C++17 the new element is returned by reference *) + let<**> astate, last = last_index path location vector astate in + let<+> astate, (elem, _) = + GenericArrayBackedCollection.element path location vector last astate + in + PulseOperations.write_id ret_id (elem, Hist.single_call path location desc) astate + + + let resize vector size : model_no_non_disj = + fun {path; location} astate -> + let desc = "std::vector::resize()" in + let<*> astate, (old_size, _) = + GenericArrayBackedCollection.to_internal_size_deref path Read location vector astate + in + (* shrinking never reallocates; when the vector may grow, assume that it reallocates without + splitting the state, as for [push_back] *) + let may_grow = + PulseArithmetic.prune_binop ~negated:true Le + (AbstractValueOperand (fst size)) + (AbstractValueOperand old_size) astate + |> SatUnsat.sat |> Option.is_some + in + let<*> astate = + if may_grow then reallocate_unless_reserved path location vector (Some Resize) ~desc astate + else Ok astate + in + let<+> astate = + GenericArrayBackedCollection.assign_size path location vector size ~desc astate + in + astate + + + let erase ~range vector iter : model_no_non_disj = + fun {path; location} astate -> + let desc = "std::vector::erase()" in + let event = Hist.call_event path location desc in + let<**> astate = + if range then SatUnsat.Sat (havoc_size path location vector ~desc astate) + else GenericArrayBackedCollection.decrease_size path location vector ~desc astate + in + let<*> astate = + reallocate_internal_array path (Hist.single_event event) vector Erase location astate + in + (* the returned iterator points to an unknown position in the vector *) + let<+> astate = + GenericArrayBackedCollection.Iterator.point_into path location event ~collection:vector ~iter + astate + in + astate end module GenericMapCollection = struct @@ -957,16 +1185,28 @@ let map_matchers = $--> BasicString.default_constructor ~desc:"std::basic_string::basic_string()" ; -"std" &:: "basic_string" &:: "operator_basic_string_view" $ capt_arg_payload $+ capt_arg_payload - $--> BasicString.constructor_rev ~desc:"std::basic_string::operator_basic_string_view()" + $--> BasicStringView.of_string ~desc:"std::basic_string::operator_basic_string_view()" ; -"std" &:: "basic_string" &:: "data" <>$ capt_arg_payload $--> BasicString.data ~desc:"std::basic_string::data()" + ; -"std" &:: "basic_string" &:: "c_str" <>$ capt_arg_payload + $--> BasicString.data ~desc:"std::basic_string::c_str()" + ; -"std" &:: "basic_string_view" &:: "basic_string_view" $ capt_arg_payload + $+ capt_arg_payload_of_prim_typ char_ptr_typ + $--> BasicStringView.constructor_from_char_ptr + ~desc:"std::basic_string_view::basic_string_view()" ; -"std" &:: "basic_string_view" &:: "basic_string_view" $ capt_arg_payload $+ capt_arg_payload_of_prim_typ char_ptr_typ - $--> BasicString.constructor_from_constant ~desc:"std::basic_string_view::basic_string_view()" - ; -"std" &:: "basic_string_view" &:: "basic_string_view" $ capt_arg_payload $+ capt_arg_payload - $--> BasicString.copy_constructor ~desc:"std::basic_string_view::basic_string_view()" + $+ capt_arg + $--> BasicStringView.constructor_from_char_ptr_and_size + ~desc:"std::basic_string_view::basic_string_view()" + ; -"std" &:: "basic_string_view" &:: "basic_string_view" $ capt_arg_payload + $+ capt_arg_payload_of_typ (-"std" &:: "basic_string_view") + $--> BasicStringView.copy_constructor ~desc:"std::basic_string_view::basic_string_view()" + ; -"std" &:: "basic_string_view" &:: "operator=" <>$ capt_arg_payload + $+ capt_arg_payload_of_typ (-"std" &:: "basic_string_view") + $--> BasicStringView.assign ~desc:"std::basic_string_view::operator=()" ; -"std" &:: "basic_string_view" &:: "data" <>$ capt_arg_payload - $--> BasicString.data ~desc:"std::basic_string_view::data()" + $--> BasicStringView.data ~desc:"std::basic_string_view::data()" ; -"std" &:: "basic_string" &:: "begin" <>$ capt_arg_payload $+ capt_arg_payload $--> BasicString.begin_ ~desc:"std::basic_string::begin()" ; -"std" &:: "basic_string" &:: "end" <>$ capt_arg_payload $+ capt_arg_payload @@ -975,6 +1215,10 @@ let map_matchers = ; -"std" &:: "basic_string" &:: "length" <>$ capt_arg_payload $--> BasicString.length ; -"std" &:: "basic_string" &:: "~basic_string" <>$ capt_arg_payload $--> BasicString.destructor ] + @ List.map Invalidation.all_std_string_functions ~f:(fun string_f -> + -"std" &:: "basic_string" + &:: Invalidation.std_string_method_name string_f + $ capt_arg $++$--> BasicString.mutator string_f |> with_non_disj ) in let folly_matchers = List.concat_map @@ -1251,27 +1495,60 @@ let simple_matchers = $+ capt_arg_payload_of_typ (-"std" &:: "vector") $+...$--> Vector.init_copy_constructor ~desc:"std::vector::vector()" |> with_non_disj - ; -"std" &:: "vector" &:: "assign" <>$ capt_arg_payload - $+...$--> Vector.invalidate_references Assign + ; -"std" &:: "vector" &:: "assign" $ capt_arg_payload $+ capt_arg $+ any_arg + $--> Vector.assign_count |> with_non_disj + ; -"std" &:: "vector" &:: "assign" $ capt_arg_payload + $+...$--> Vector.invalidate_references_unknown_size Assign |> with_non_disj ; -"std" &:: "vector" &:: "at" <>$ capt_arg_payload $+ capt_arg_payload $--> Vector.at ~desc:"std::vector::at()" |> with_non_disj + ; -"std" &:: "vector" &:: "back" <>$ capt_arg_payload + $--> Vector.back ~desc:"std::vector::back()" + |> with_non_disj ; -"std" &:: "vector" &:: "begin" <>$ capt_arg_payload $+ capt_arg_payload - $--> Vector.vector_begin |> with_non_disj - ; -"std" &:: "vector" &:: "end" <>$ capt_arg_payload $+ capt_arg_payload $--> Vector.vector_end + $--> Vector.vector_begin ~desc:"std::vector::begin()" + |> with_non_disj + ; -"std" &:: "vector" &:: "cbegin" <>$ capt_arg_payload $+ capt_arg_payload + $--> Vector.vector_begin ~desc:"std::vector::cbegin()" + |> with_non_disj + ; -"std" &:: "vector" &:: "end" <>$ capt_arg_payload $+ capt_arg_payload + $--> Vector.vector_end ~desc:"std::vector::end()" + |> with_non_disj + ; -"std" &:: "vector" &:: "cend" <>$ capt_arg_payload $+ capt_arg_payload + $--> Vector.vector_end ~desc:"std::vector::cend()" |> with_non_disj ; -"std" &:: "vector" &:: "clear" <>$ capt_arg_payload $--> Vector.invalidate_references Clear |> with_non_disj + ; -"std" &:: "vector" &:: "data" <>$ capt_arg_payload + $--> Vector.data ~desc:"std::vector::data()" + |> with_non_disj ; -"std" &:: "vector" &:: "emplace" $ capt_arg_payload - $+...$--> Vector.invalidate_references Emplace + $+...$--> Vector.invalidate_references_one_more Emplace |> with_non_disj ; -"std" &:: "vector" &:: "emplace_back" $ capt_arg_payload - $+...$--> Vector.push_back_cpp ~vector_f:EmplaceBack ~desc:"std::vector::emplace_back()" + $+...$--> Vector.emplace_back ~desc:"std::vector::emplace_back()" + |> with_non_disj + ; (* the returned iterator is passed as the last argument *) + -"std" &:: "vector" &:: "erase" <>$ capt_arg_payload $+ any_arg $+ capt_arg_payload + $--> Vector.erase ~range:false |> with_non_disj + ; -"std" &:: "vector" &:: "erase" <>$ capt_arg_payload $+ any_arg $+ any_arg $+ capt_arg_payload + $--> Vector.erase ~range:true |> with_non_disj + ; -"std" &:: "vector" &:: "front" <>$ capt_arg_payload + $--> Vector.front ~desc:"std::vector::front()" + |> with_non_disj + ; -"std" &:: "vector" &:: "insert" $ capt_arg_payload $+ any_arg + $+ any_arg_of_typ (-"std" &:: "initializer_list") + $+ any_arg + $--> Vector.invalidate_references_unknown_size Insert + |> with_non_disj + ; (* [insert(pos, value)], the returned iterator is passed as the last argument *) + -"std" &:: "vector" &:: "insert" $ capt_arg_payload $+ any_arg $+ any_arg $+ any_arg + $--> Vector.invalidate_references_one_more Insert |> with_non_disj - ; -"std" &:: "vector" &:: "insert" <>$ capt_arg_payload - $+...$--> Vector.invalidate_references Insert + ; -"std" &:: "vector" &:: "insert" $ capt_arg_payload + $+...$--> Vector.invalidate_references_unknown_size Insert |> with_non_disj ; -"std" &:: "vector" &:: "operator=" <>$ capt_arg_payload $+...$--> Vector.invalidate_references_with_ret Assign @@ -1293,6 +1570,8 @@ let simple_matchers = |> with_non_disj ; -"std" &:: "vector" &:: "reserve" <>$ capt_arg_payload $+...$--> Vector.reserve |> with_non_disj + ; -"std" &:: "vector" &:: "resize" <>$ capt_arg_payload $+ capt_arg_payload + $+...$--> Vector.resize |> with_non_disj ; -"std" &:: "vector" &:: "size" $ capt_arg_payload $--> GenericArrayBackedCollection.size ~desc:"std::vector::size()" |> with_non_disj diff --git a/infer/src/pulse/PulseModelsCpp.mli b/infer/src/pulse/PulseModelsCpp.mli index 2f4dc82693..da70a17d1e 100644 --- a/infer/src/pulse/PulseModelsCpp.mli +++ b/infer/src/pulse/PulseModelsCpp.mli @@ -23,6 +23,10 @@ module Vector : sig val push_back : AbstractValue.t * ValueHistory.t -> desc:string -> model_no_non_disj end +module GenericMapCollection : sig + val pair_second_access : Typ.t -> Typ.t -> Access.t +end + module Function : sig val operator_call : deref_lambda_ptr:bool diff --git a/infer/src/pulse/PulseModelsGenericArrayBackedCollection.ml b/infer/src/pulse/PulseModelsGenericArrayBackedCollection.ml index 4443566de4..82fbe31d3a 100644 --- a/infer/src/pulse/PulseModelsGenericArrayBackedCollection.ml +++ b/infer/src/pulse/PulseModelsGenericArrayBackedCollection.ml @@ -35,6 +35,13 @@ let assign_size_constant path location this ~constant ~desc astate = PulseArithmetic.and_eq_int (fst value) constant astate +let assign_size path location this (size, size_hist) ~desc astate = + let* astate, size_pointer = to_internal_size path Read location this astate in + PulseOperations.write_deref path location ~ref:size_pointer + ~obj:(size, Hist.add_call path location desc size_hist) + astate + + let access = Access.FieldAccess field let eval path mode location collection astate = @@ -132,6 +139,30 @@ module Iterator = struct (astate, pointer, index) + let check_not_end location ?index pointer astate = + if + AddressAttributes.is_end_of_collection (fst pointer) astate + || Option.exists index ~f:(fun (index, _) -> + AddressAttributes.is_end_of_collection index astate ) + then + let invalidation_trace = Trace.Immediate {location; history= ValueHistory.epoch} in + let access_trace = Trace.Immediate {location; history= snd pointer} in + FatalError + ( ReportableError + { diagnostic= + Diagnostic.AccessToInvalidAddress + { calling_context= [] + ; invalid_address= Decompiler.find (fst pointer) astate + ; invalidation= EndIterator + ; invalidation_trace + ; access_trace + ; may_depend_on_an_unknown_value= astate.AbductiveDomain.unknown_values + ; must_be_valid_reason= None } + ; astate } + , [] ) + else Ok astate + + let to_elem_pointed_by_iterator path mode ?(step = None) location iterator astate = let* astate, pointer = to_internal_pointer path Read location iterator astate in let* astate, index = @@ -140,28 +171,12 @@ module Iterator = struct (* Check if not end iterator *) let is_minus_minus = match step with Some `MinusMinus -> true | _ -> false in let* astate = - if AddressAttributes.is_end_of_collection (fst pointer) astate && not is_minus_minus then - let invalidation_trace = Trace.Immediate {location; history= ValueHistory.epoch} in - let access_trace = Trace.Immediate {location; history= snd pointer} in - FatalError - ( ReportableError - { diagnostic= - Diagnostic.AccessToInvalidAddress - { calling_context= [] - ; invalid_address= Decompiler.find (fst pointer) astate - ; invalidation= EndIterator - ; invalidation_trace - ; access_trace - ; may_depend_on_an_unknown_value= astate.AbductiveDomain.unknown_values - ; must_be_valid_reason= None } - ; astate } - , [] ) - else Ok astate + if is_minus_minus then Ok astate else check_not_end location ~index pointer astate in (* We do not want to create internal array if iterator pointer has an invalid value *) let* astate = PulseOperations.check_addr_access path Read location index astate in let+ astate, elem = element path location iterator (fst index) astate in - (astate, pointer, elem) + (astate, pointer, index, elem) let construct path location event ~init ~ref astate = @@ -184,15 +199,155 @@ module Iterator = struct astate - let operator_compare comparison ~desc iter_lhs iter_rhs : model_no_non_disj = - fun {path; location; ret= ret_id, _} astate -> + let write_position path location ~iter ~arr ~position pointer_hist astate = + let pointer = (AbstractValue.mk_fresh (), pointer_hist) in + PulseOperations.write_deref_field path location ~ref:iter field ~obj:(arr, pointer_hist) astate + >>= PulseOperations.write_field path location ~ref:iter internal_pointer ~obj:pointer + >>= PulseOperations.write_deref path location ~ref:pointer ~obj:position + + + let point_into path location event ~collection ~iter ?index astate = + let pointer_hist = Hist.add_event event (snd iter) in + let* astate, (arr_addr, _arr_hist) = eval path Read location collection astate in + let* astate, position = + match index with + | Some index -> + eval_element path location (arr_addr, pointer_hist) index astate + | None -> + (* as in [operator_step], an array element at a fresh index would be added to the + pre-condition of every caller when the collection is a parameter *) + Ok (astate, (AbstractValue.mk_fresh (), pointer_hist)) + in + write_position path location ~iter ~arr:arr_addr ~position pointer_hist astate + + + (* string iterators carry the taint of their string, see [BasicString.iterator_common] in + [PulseModelsCpp] *) + let propagate_taint ~src ~dst astate = + if AbstractValue.equal (fst src) (fst dst) then astate + else + AddressAttributes.add_one (fst dst) + (PropagateTaintFrom (InternalModel, [{v= fst src; history= snd src}])) + astate + + + (** copy the fields of the library's iterator class from [src] to [dst], shifted by [offset] if + given, for models that replace its functions, e.g. for [base()] *) + let write_own_fields tenv path location event iterator_class ?offset ~src ~dst astate = + let fields = + Option.bind iterator_class ~f:(Tenv.lookup tenv) + |> Option.value_map ~default:[] ~f:(fun {Struct.fields} -> fields) + in + PulseOperationResult.list_fold fields ~init:astate ~f:(fun astate {Struct.name= field; typ} -> + match typ.Typ.desc with + | Tstruct _ -> + (* not needed for the iterator classes modelled here, which wrap a pointer *) + SatUnsat.Sat (Ok astate) + | _ -> + let=* astate, (value, hist) = + PulseOperations.eval_deref_access path Read location src (FieldAccess field) astate + in + let+* astate, value = + match offset with + | None -> + SatUnsat.Sat (Ok (astate, value)) + | Some (binop, n) -> + PulseArithmetic.eval_binop (AbstractValue.mk_fresh ()) binop + (AbstractValueOperand value) n astate + in + PulseOperations.write_deref_field path location ~ref:dst field + ~obj:(value, Hist.add_event event hist) + astate ) + + + let assign ~desc this other : model_no_non_disj = + fun {analysis_data= {tenv}; path; location; callee_procname; ret= ret_id, _} astate -> let event = Hist.call_event path location desc in - let<*> astate, _, (index_lhs, _) = - to_internal_pointer_deref path Read location iter_lhs astate + let<*> astate = construct path location event ~init:other ~ref:this astate in + let<++> astate = + write_own_fields tenv path location event + (Procname.get_class_type_name callee_procname) + ~src:other ~dst:this astate in - let<*> astate, _, (index_rhs, _) = - to_internal_pointer_deref path Read location iter_rhs astate + PulseOperations.write_id ret_id this astate + + + let class_of_arg {FuncArg.typ} = + match typ.Typ.desc with Tptr (typ, _) -> Typ.name typ | _ -> Typ.name typ + + + (** make [dst] point [n] elements after ([PlusPI]) or before ([MinusPI]) [src] *) + let apply_offset {analysis_data= {tenv}; path; location} ~desc binop + (FuncArg.{arg_payload= src} as src_arg) n ~dst astate = + let event = Hist.call_event path location desc in + let=* astate, pointer, (index, _) = to_internal_pointer_deref path Read location src astate in + (* as in [operator_step], so that a position computed back to the one of [end()], e.g. by + [v.end() - 1 + 1], is still detected *) + let astate = + if AddressAttributes.is_end_of_collection (fst pointer) astate then + AddressAttributes.mark_as_end_of_collection index astate + else astate + in + let** astate, position = + PulseArithmetic.eval_binop (AbstractValue.mk_fresh ()) binop (AbstractValueOperand index) n + astate + in + let=* astate, (arr_addr, _) = eval path Read location src astate in + let pointer_hist = Hist.add_event event (snd dst) in + let=* astate = + write_position path location ~iter:dst ~arr:arr_addr ~position:(position, pointer_hist) + pointer_hist astate in + let astate = propagate_taint ~src ~dst astate in + write_own_fields tenv path location event (class_of_arg src_arg) ~offset:(binop, n) ~src ~dst + astate + + + (** [operator+=] and [operator-=] *) + let operator_offset_assign binop ~desc (FuncArg.{arg_payload= this} as this_arg) n : + model_no_non_disj = + fun ({ret= ret_id, _} as model_data) astate -> + let<++> astate = + apply_offset model_data ~desc binop this_arg (AbstractValueOperand (fst n)) ~dst:this astate + in + PulseOperations.write_id ret_id this astate + + + let offset ~desc binop iter n ~dst : model_no_non_disj = + fun model_data astate -> + let<++> astate = apply_offset model_data ~desc binop iter n ~dst astate in + astate + + + (** [operator+], [operator-], [std::next] and [std::prev] *) + let operator_offset binop ~desc iter (n, _) ret = + offset ~desc binop iter (AbstractValueOperand n) ~dst:ret + + + (** libc++'s overload for [std::prev(it)] *) + let prev_one ~desc iter ret = offset ~desc MinusPI iter (ConstOperand (Cint IntLit.one)) ~dst:ret + + let advance ~desc (FuncArg.{arg_payload= iter} as iter_arg) (n, _) = + offset ~desc PlusPI iter_arg (AbstractValueOperand n) ~dst:iter + + + (* no "not found" case for search functions since callers often know that the element is there, + as in the model of [folly::F14FastMap::find] *) + let position_in_range ~desc first args : model_no_non_disj = + fun {path; location} astate -> + (* the returned iterator is passed as the last argument *) + match List.last args with + | None -> + [Ok (ContinueProgram astate)] + | Some ret -> + let event = Hist.call_event path location desc in + let<+> astate = point_into path location event ~collection:first ~iter:ret astate in + propagate_taint ~src:first ~dst:ret astate + + + let compare_values comparison ~desc value_lhs value_rhs : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in let ret_val = AbstractValue.mk_fresh () in let astate = PulseOperations.write_id ret_id (ret_val, Hist.single_event event) astate in let ret_val_equal, ret_val_notequal = @@ -204,23 +359,34 @@ module Iterator = struct in let astate_equal = PulseArithmetic.and_eq_int ret_val ret_val_equal astate - >>== PulseArithmetic.prune_binop ~negated:false Eq (AbstractValueOperand index_lhs) - (AbstractValueOperand index_rhs) + >>== PulseArithmetic.prune_binop ~negated:false Eq (AbstractValueOperand value_lhs) + (AbstractValueOperand value_rhs) >>|| ExecutionDomain.continue in let astate_notequal = PulseArithmetic.and_eq_int ret_val ret_val_notequal astate - >>== PulseArithmetic.prune_binop ~negated:false Ne (AbstractValueOperand index_lhs) - (AbstractValueOperand index_rhs) + >>== PulseArithmetic.prune_binop ~negated:false Ne (AbstractValueOperand value_lhs) + (AbstractValueOperand value_rhs) >>|| ExecutionDomain.continue in SatUnsat.to_list astate_equal @ SatUnsat.to_list astate_notequal + let operator_compare comparison ~desc iter_lhs iter_rhs : model_no_non_disj = + fun ({path; location} as model_data) astate -> + let<*> astate, _, (index_lhs, _) = + to_internal_pointer_deref path Read location iter_lhs astate + in + let<*> astate, _, (index_rhs, _) = + to_internal_pointer_deref path Read location iter_rhs astate + in + compare_values comparison ~desc index_lhs index_rhs model_data astate + + let operator_star ~desc iter : model_no_non_disj = fun {path; location; ret} astate -> let event = Hist.call_event path location desc in - let<+> astate, pointer, (elem, _) = + let<+> astate, pointer, _, (elem, _) = to_elem_pointed_by_iterator path Read location iter astate in PulseOperations.write_id (fst ret) (elem, Hist.add_event event (snd pointer)) astate @@ -229,24 +395,99 @@ module Iterator = struct let operator_step step ~desc iter : model_no_non_disj = fun {path; location} astate -> let event = Hist.call_event path location desc in - let index_new = AbstractValue.mk_fresh () in - let<*> astate, pointer, _ = + let<*> astate, pointer, (index, _), _ = to_elem_pointed_by_iterator path Read ~step:(Some step) location iter astate in + (* positions are related by the steps, so marking the position of [end()] detects stepping + back to it, as in [--it; ++it] *) + let astate = + if AddressAttributes.is_end_of_collection (fst pointer) astate then + AddressAttributes.mark_as_end_of_collection index astate + else astate + in + let binop = + match step with `PlusPlus -> Binop.PlusA None | `MinusMinus -> Binop.MinusA None + in + let<**> astate, index_new = + PulseArithmetic.eval_binop (AbstractValue.mk_fresh ()) binop (AbstractValueOperand index) + (ConstOperand (Cint IntLit.one)) astate + in + (* the internal pointer is shared with the copies of the iterator, and with the other [end()] + iterators of the collection, so we replace it instead of writing through it *) + let pointer_new = (AbstractValue.mk_fresh (), snd pointer) in let<+> astate = - PulseOperations.write_deref path location ~ref:pointer - ~obj:(index_new, Hist.add_event event (snd pointer)) - astate + PulseOperations.write_field path location ~ref:iter internal_pointer ~obj:pointer_new astate + >>= PulseOperations.write_deref path location ~ref:pointer_new + ~obj:(index_new, Hist.add_event event (snd pointer)) in astate end +(* functions of [] that return an iterator into the range starting at their first + argument; the ones that reorder the range, e.g. [std::remove_if], are left as unknown calls, which + havoc the range *) +let algorithm_matchers = + let open ProcnameDispatcher.Call in + let position_in_range name = + -"std" &:: name + $ capt_arg_payload_of_typ_exists [-"std" &:: "__wrap_iter"; -"__gnu_cxx" &:: "__normal_iterator"] + $+++$--> Iterator.position_in_range ~desc:(Printf.sprintf "std::%s()" name) + in + List.map ~f:position_in_range + [ "adjacent_find" + ; "find" + ; "find_end" + ; "find_first_of" + ; "find_if" + ; "find_if_not" + ; "is_heap_until" + ; "is_sorted_until" + ; "lower_bound" + ; "max_element" + ; "min_element" + ; "partition_point" + ; "search" + ; "search_n" + ; "upper_bound" ] + + +let arithmetic_matchers namespace class_name = + let open ProcnameDispatcher.Call in + [ -namespace &:: class_name &:: "operator+" <>$ capt_arg $+ capt_arg_payload $+ capt_arg_payload + $--> Iterator.operator_offset PlusPI ~desc:"iterator operator+" + ; -namespace &:: class_name &:: "operator-" <>$ capt_arg $+ capt_arg_payload $+ capt_arg_payload + $--> Iterator.operator_offset MinusPI ~desc:"iterator operator-" + ; -namespace &:: class_name &:: "operator+=" <>$ capt_arg $+ capt_arg_payload + $--> Iterator.operator_offset_assign PlusPI ~desc:"iterator operator+=" + ; -namespace &:: class_name &:: "operator-=" <>$ capt_arg $+ capt_arg_payload + $--> Iterator.operator_offset_assign MinusPI ~desc:"iterator operator-=" ] + + +let iterator_function_matchers = + let open ProcnameDispatcher.Call in + let iterator () = + capt_arg_of_typ_exists [-"std" &:: "__wrap_iter"; -"__gnu_cxx" &:: "__normal_iterator"] + in + [ -"std" &:: "advance" $ iterator () $+ capt_arg_payload + $--> Iterator.advance ~desc:"std::advance()" + ; -"std" &:: "next" $ iterator () $+ capt_arg_payload $+ capt_arg_payload + $--> Iterator.operator_offset PlusPI ~desc:"std::next()" + ; -"std" &:: "prev" $ iterator () $+ capt_arg_payload $+ capt_arg_payload + $--> Iterator.operator_offset MinusPI ~desc:"std::prev()" + ; -"std" &:: "prev" $ iterator () $+ capt_arg_payload $--> Iterator.prev_one ~desc:"std::prev()" + ] + + let matchers : matcher list = let open ProcnameDispatcher.Call in [ -"std" &:: "__wrap_iter" &:: "__wrap_iter" $ capt_arg_payload $+ capt_arg_payload $+...$--> Iterator.constructor ~desc:"iterator constructor" + ; -"std" &:: "__wrap_iter" &:: "operator=" $ capt_arg_payload $+ capt_arg_payload + $--> Iterator.assign ~desc:"iterator operator=" ; -"std" &:: "__wrap_iter" &:: "operator*" <>$ capt_arg_payload $--> Iterator.operator_star ~desc:"iterator operator*" + ; -"std" &:: "__wrap_iter" &:: "operator->" <>$ capt_arg_payload + $--> Iterator.operator_star ~desc:"iterator operator->" ; -"std" &:: "__wrap_iter" &:: "operator++" <>$ capt_arg_payload $--> Iterator.operator_step `PlusPlus ~desc:"iterator operator++" ; -"std" &:: "__wrap_iter" &:: "operator--" <>$ capt_arg_payload @@ -262,8 +503,12 @@ let matchers : matcher list = ; -"__gnu_cxx" &:: "__normal_iterator" &:: "__normal_iterator" $ capt_arg_payload $+ capt_arg_payload $+...$--> Iterator.constructor ~desc:"iterator constructor" + ; -"__gnu_cxx" &:: "__normal_iterator" &:: "operator=" $ capt_arg_payload $+ capt_arg_payload + $--> Iterator.assign ~desc:"iterator operator=" ; -"__gnu_cxx" &:: "__normal_iterator" &:: "operator*" <>$ capt_arg_payload $--> Iterator.operator_star ~desc:"iterator operator*" + ; -"__gnu_cxx" &:: "__normal_iterator" &:: "operator->" <>$ capt_arg_payload + $--> Iterator.operator_star ~desc:"iterator operator->" ; -"__gnu_cxx" &:: "__normal_iterator" &:: "operator++" <>$ capt_arg_payload $--> Iterator.operator_step `PlusPlus ~desc:"iterator operator++" ; -"__gnu_cxx" &:: "__normal_iterator" &:: "operator--" <>$ capt_arg_payload @@ -276,5 +521,8 @@ let matchers : matcher list = $ capt_arg_payload_of_typ (-"__gnu_cxx" &:: "__normal_iterator") $+ capt_arg_payload_of_typ (-"__gnu_cxx" &:: "__normal_iterator") $--> Iterator.operator_compare `NotEqual ~desc:"iterator operator!=" ] + @ arithmetic_matchers "std" "__wrap_iter" + @ arithmetic_matchers "__gnu_cxx" "__normal_iterator" + @ iterator_function_matchers @ algorithm_matchers |> List.map ~f:(ProcnameDispatcher.Call.contramap_arg_payload ~f:ValueOrigin.addr_hist) |> List.map ~f:(ProcnameDispatcher.Call.map_matcher ~f:lift_model) diff --git a/infer/src/pulse/PulseModelsGenericArrayBackedCollection.mli b/infer/src/pulse/PulseModelsGenericArrayBackedCollection.mli index 3fe4968863..8450c1ef04 100644 --- a/infer/src/pulse/PulseModelsGenericArrayBackedCollection.mli +++ b/infer/src/pulse/PulseModelsGenericArrayBackedCollection.mli @@ -80,6 +80,15 @@ val to_internal_size_deref : -> AbductiveDomain.t -> (AbductiveDomain.t * (AbstractValue.t * ValueHistory.t)) AccessResult.t +val assign_size : + PathContext.t + -> Location.t + -> AbstractValue.t * ValueHistory.t + -> AbstractValue.t * ValueHistory.t + -> desc:string + -> AbductiveDomain.t + -> AbductiveDomain.t AccessResult.t + val assign_size_constant : PathContext.t -> Location.t @@ -92,6 +101,15 @@ val assign_size_constant : module Iterator : sig val internal_pointer : Fieldname.t + val check_not_end : + Location.t + -> ?index:AbstractValue.t * ValueHistory.t + -> AbstractValue.t * ValueHistory.t + -> AbductiveDomain.t + -> AbductiveDomain.t AccessResult.t + (** report an access to the end iterator of a collection if the value (or [index]) is the + past-the-end value of the collection *) + val to_internal_pointer : PathContext.t -> access_mode @@ -100,6 +118,10 @@ module Iterator : sig -> AbductiveDomain.t -> (AbductiveDomain.t * (AbstractValue.t * ValueHistory.t)) AccessResult.t + val compare_values : + [< `Equal | `NotEqual] -> desc:string -> AbstractValue.t -> AbstractValue.t -> model_no_non_disj + (** [operator==] or [operator!=] on two iterators whose positions are the given values *) + val construct : PathContext.t -> Location.t @@ -108,4 +130,16 @@ module Iterator : sig -> ref:AbstractValue.t * ValueHistory.t -> AbductiveDomain.t -> AbductiveDomain.t AccessResult.t + + val point_into : + PathContext.t + -> Location.t + -> ValueHistory.event + -> collection:AbstractValue.t * ValueHistory.t + -> iter:AbstractValue.t * ValueHistory.t + -> ?index:AbstractValue.t + -> AbductiveDomain.t + -> AbductiveDomain.t AccessResult.t + (** make [iter] point to the element at [index], or at an unknown position if not given, in the + backing array of [collection], which is either a collection or an iterator into it *) end diff --git a/infer/src/pulse/PulseModelsOptional.ml b/infer/src/pulse/PulseModelsOptional.ml index 6bb3a858e1..4c303d6ab2 100644 --- a/infer/src/pulse/PulseModelsOptional.ml +++ b/infer/src/pulse/PulseModelsOptional.ml @@ -346,9 +346,6 @@ let matchers : matcher list = $--> copy_assignment ~desc:"folly::Optional::assign(folly::Optional arg)" ; -"folly" &:: "Optional" &:: "assign" &++> assign_value ~desc:"folly::Optional::assign(Value arg)" - ; -"folly" &:: "Optional" &:: "emplace<>" $ capt_arg_payload - $+...$--> emplace ~desc:"folly::Optional::emplace()" - |> with_non_disj ; -"folly" &:: "Optional" &:: "emplace" $ capt_arg_payload $+...$--> emplace ~desc:"folly::Optional::emplace()" |> with_non_disj @@ -396,9 +393,6 @@ let matchers : matcher list = $--> copy_assignment ~desc:"std::optional::operator=(std::optional arg)" ; -"std" &:: "optional" &:: "operator=" &++> assign_value ~desc:"std::optional::operator=(Value arg)" - ; -"std" &:: "optional" &:: "emplace<>" $ capt_arg_payload - $+...$--> emplace ~desc:"std::optional::emplace()" - |> with_non_disj ; -"std" &:: "optional" &:: "emplace" $ capt_arg_payload $+...$--> emplace ~desc:"std::optional::emplace()" |> with_non_disj diff --git a/infer/src/pulse/PulseModelsStdContainers.ml b/infer/src/pulse/PulseModelsStdContainers.ml new file mode 100644 index 0000000000..ebea2b2525 --- /dev/null +++ b/infer/src/pulse/PulseModelsStdContainers.ml @@ -0,0 +1,629 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd +open PulseBasicInterface +open PulseDomainInterface +open PulseOperationResult.Import +open PulseModelsImport +module Collection = PulseModelsGenericArrayBackedCollection +module GenericMapCollection = PulseModelsCpp.GenericMapCollection + +(* Models of [std::deque] and of the node-based containers ([std::list], [std::map], [std::set], + [std::unordered_map], ...), and of their libc++ iterators. On libstdc++, whose iterators are not + modelled, [begin()], [end()], [find()] and [erase()] are not modelled either; the other models + apply. + + The elements of a container are the cells of its backing array so that [clear()] can invalidate + all the elements known to the analysis. An iterator stores the address of its element, or the + past-the-end value of the container, in [node_field], and the backing array of the container in + [Collection.field]. Insertions do not invalidate the elements of the node-based containers; the + invalidation of the iterators of an unordered container by rehashing is not modelled. + + [std::deque] iterators also store the current [token_field] of the container: insertions into a + deque invalidate the token, that is all the iterators, but no element (insertions in the middle of + a deque also invalidate references, which is not modelled). + + [begin()] and [find()] return the end iterator only when the container is known to be empty so + that a lookup is not reported for lack of a comparison with [end()]. *) + +let node_field = Fieldname.make PulseOperations.pulse_model_type "__infer_node" + +let token_field = Fieldname.make PulseOperations.pulse_model_type "__infer_iterators_token" + +let desc class_name name = Printf.sprintf "std::%s::%s()" class_name name + +let has_token (container : Invalidation.std_container) = + match container with Deque -> true | _ -> false + + +let load_field path location obj field astate = + PulseOperations.eval_deref_access path Read location obj (FieldAccess field) astate + + +let store_field path location event obj field (value, hist) astate = + PulseOperations.write_deref_field path location ~ref:obj field + ~obj:(value, Hist.add_event event hist) + astate + + +let end_function = Formula.Procname (Procname.from_string_c_fun "__infer_end_of_collection") + +(* The past-the-end value of a container is a function of its backing array rather than a cell of + it: comparing an element, abduced in the pre, with a value of the pre would be an assumption on + the heap of the caller that makes all the paths after a loop over a container parameter latent, + and a cell added in the post only would hide the writes through the elements from impurity. *) +let eval_end path location container astate = + let=* astate, arr = Collection.eval path Read location container astate in + let end_value = AbstractValue.mk_fresh () in + let++ astate = + PulseArithmetic.and_equal (AbstractValueOperand end_value) + (FunctionApplicationOperand {f= end_function; actuals= [fst arr]}) + astate + in + (AddressAttributes.mark_as_end_of_collection end_value astate, (end_value, snd arr)) + + +let fresh_element path location container astate = + Collection.element path location container (AbstractValue.mk_fresh ()) astate + + +let set_size_positive path location event container astate = + let size = AbstractValue.mk_fresh () in + let=* astate = + PulseOperations.write_deref_field path location ~ref:container Collection.size_field + ~obj:(size, Hist.single_event event) + astate + in + PulseArithmetic.and_positive size astate + + +let make_iterator ~has_token path location event container iter elem astate = + let* astate, arr = Collection.eval path Read location container astate in + let* astate = store_field path location event iter Collection.field arr astate in + let* astate = store_field path location event iter node_field elem astate in + if has_token then + let* astate, token = load_field path location container token_field astate in + store_field path location event iter token_field token astate + else Ok astate + + +let copy_iterator ~has_token path location event ~src ~dst astate = + let fields = Collection.field :: node_field :: (if has_token then [token_field] else []) in + PulseResult.list_fold fields ~init:astate ~f:(fun astate field -> + let* astate, value = load_field path location src field astate in + store_field path location event dst field value astate ) + + +(** check that [iter] is valid, and that it is not the end iterator unless [allow_end], then return + its element and the backing array of its container *) +let check_iterator ~has_token ~allow_end path location iter astate = + let* astate, elem = load_field path location iter node_field astate in + let* astate = + if allow_end then Ok astate else Collection.Iterator.check_not_end location elem astate + in + let* astate = + if has_token then + let* astate, token = load_field path location iter token_field astate in + PulseOperations.check_addr_access path NoAccess location token astate + else Ok astate + in + let* astate = PulseOperations.check_addr_access path NoAccess location elem astate in + (* [clear()] invalidates the backing array, hence the iterators obtained before *) + let* astate, arr = load_field path location iter Collection.field astate in + let+ astate = PulseOperations.check_addr_access path NoAccess location arr astate in + (astate, elem, arr) + + +(* the fields of the element are invalidated too, e.g. the mapped value of a map entry *) +let invalidate_element path location cause elem astate = + let rec invalidate_fields (visited, astate) addr = + Memory.fold_edges (fst addr) astate ~init:(visited, astate) + ~f:(fun (visited, astate) (access, field_addr) -> + match (access : Access.t) with + | FieldAccess _ when not (AbstractValue.Set.mem (fst field_addr) visited) -> + let astate = + PulseOperations.invalidate path + (MemoryAccess {pointer= addr; access; hist_obj_default= snd field_addr}) + location cause field_addr astate + in + invalidate_fields (AbstractValue.Set.add (fst field_addr) visited, astate) field_addr + | _ -> + (visited, astate) ) + in + let astate = PulseOperations.invalidate path UntraceableAccess location cause elem astate in + invalidate_fields (AbstractValue.Set.singleton (fst elem), astate) elem |> snd + + +module Iterator = struct + let constructor this other ~has_token ~desc : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let<+> astate = copy_iterator ~has_token path location event ~src:other ~dst:this astate in + astate + + + let operator_assign this other ~has_token ~desc : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<+> astate = copy_iterator ~has_token path location event ~src:other ~dst:this astate in + PulseOperations.write_id ret_id (fst this, Hist.add_event event (snd this)) astate + + + let operator_star iter ~has_token ~desc : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<+> astate, (elem, hist), _ = + check_iterator ~has_token ~allow_end:false path location iter astate + in + PulseOperations.write_id ret_id (elem, Hist.add_event event hist) astate + + + let step ~has_token step path location event iter astate = + let allow_end = match step with `PlusPlus -> false | `MinusMinus -> true in + let* astate, _, arr = check_iterator ~has_token ~allow_end path location iter astate in + let* astate, elem = + Collection.eval_element path location arr (AbstractValue.mk_fresh ()) astate + in + store_field path location event iter node_field elem astate + + + let operator_step step_ iter ~has_token ~desc : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<+> astate = step ~has_token step_ path location event iter astate in + PulseOperations.write_id ret_id (fst iter, Hist.add_event event (snd iter)) astate + + + (** [it++] and [it--] return a copy of the iterator before the step *) + let operator_step_postfix step_ iter ret_iter ~has_token ~desc : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let<+> astate = + let* astate = copy_iterator ~has_token path location event ~src:iter ~dst:ret_iter astate in + step ~has_token step_ path location event iter astate + in + astate + + + let operator_compare comparison ~desc iter_lhs iter_rhs : model_no_non_disj = + fun ({path; location} as model_data) astate -> + let<*> astate, (elem_lhs, _) = load_field path location iter_lhs node_field astate in + let<*> astate, (elem_rhs, _) = load_field path location iter_rhs node_field astate in + Collection.Iterator.compare_values comparison ~desc elem_lhs elem_rhs model_data astate +end + +let begin_or_find this iter container ~desc : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + let=* astate, (size, _) = Collection.to_internal_size_deref path Read location this astate in + let** astate, elem = + if PulseArithmetic.is_known_zero astate size then eval_end path location this astate + else Sat (fresh_element path location this astate) + in + Sat (make_iterator ~has_token:(has_token container) path location event this iter elem astate) + in + astate + + +let end_ this iter container ~desc : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + let** astate, end_value = eval_end path location this astate in + Sat + (make_iterator ~has_token:(has_token container) path location event this iter end_value astate) + in + astate + + +let erase this pos ret_iter container ~desc : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let has_token = has_token container in + let<++> astate = + let=* astate, elem, _ = check_iterator ~has_token ~allow_end:false path location pos astate in + let astate = invalidate_element path location (StdContainer (container, Erase)) elem astate in + let+* astate = Collection.decrease_size path location this ~desc astate in + let* astate, next = fresh_element path location this astate in + make_iterator ~has_token path location event this ret_iter next astate + in + astate + + +let clear this container ~desc : model_no_non_disj = + fun {path; location} astate -> + let cause = Invalidation.StdContainer (container, Clear) in + let<++> astate = + let=* astate, arr = Collection.eval path NoAccess location this astate in + let astate = + Memory.fold_edges (fst arr) astate ~init:astate ~f:(fun astate (access, elem) -> + match (access : Access.t) with + (* an element equal to [end()] is the past-the-end value, which [end()] keeps returning *) + | ArrayAccess _ when not (AddressAttributes.is_end_of_collection (fst elem) astate) -> + invalidate_element path location cause elem astate + | _ -> + astate ) + |> PulseOperations.invalidate_deref_access path location cause this Collection.access + in + let=* astate = + PulseOperations.havoc_deref_field path location this Collection.field + (Hist.single_call path location desc) + astate + in + Collection.assign_size_constant path location this ~constant:IntLit.zero ~desc astate + in + astate + + +(** [count()] and [contains()] return 0 when the container is known to be empty *) +let count ~desc this : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let ret_val = AbstractValue.mk_fresh () in + let<++> astate = + let=* astate, (size, _) = Collection.to_internal_size_deref path Read location this astate in + let astate = + PulseOperations.write_id ret_id (ret_val, Hist.single_call path location desc) astate + in + if PulseArithmetic.is_known_zero astate size then + PulseArithmetic.and_eq_int ret_val IntLit.zero astate + else PulseArithmetic.and_nonnegative ret_val astate + in + astate + + +(* [at()], [front()], and [back()] succeed only on non-empty containers; this is assumed rather + than pruned, since a pruned size coming from the caller would make all the caller's later issues + latent *) +let assume_non_empty path location this astate = + let=* astate, (size, _) = Collection.to_internal_size_deref path Read location this astate in + PulseArithmetic.and_positive size astate + + +(** [front()] and [back()] *) +let element_reference ~desc this : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + let** astate = assume_non_empty path location this astate in + let=+ astate, (elem, hist) = fresh_element path location this astate in + Ok (PulseOperations.write_id ret_id (elem, Hist.add_event event hist) astate) + in + astate + + +(** [operator[]] and [at()] of maps return a reference to the mapped value of an element; + [operator[]] inserts an element if needed *) +let mapped_value_reference ~inserts ~desc this : model_no_non_disj = + fun {path; location; callee_procname; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + let=* astate, elem = fresh_element path location this astate in + let=* astate, (value, hist) = + match Procname.get_class_type_name callee_procname with + | Some (CppClass {template_spec_info= Template {args= TType key_t :: TType value_t :: _}}) -> + PulseOperations.eval_access path Read location elem + (GenericMapCollection.pair_second_access key_t value_t) + astate + | _ -> + Ok (astate, elem) + in + let astate = + PulseOperations.write_id ret_id (value, Hist.add_event event hist) astate + |> Decompiler.add_call_source value (Call callee_procname) [(this, StdTyp.void)] + in + if inserts then set_size_positive path location event this astate + else assume_non_empty path location this astate + in + astate + + +(* the user-facing iterator classes of the modelled libc++ containers *) +let iterators = + [ "__deque_iterator" + ; "__hash_const_iterator" + ; "__hash_map_const_iterator" + ; "__hash_map_iterator" + ; "__list_const_iterator" + ; "__list_iterator" + ; "__map_const_iterator" + ; "__map_iterator" + ; "__tree_const_iterator" ] + + +let containers : (string * Invalidation.std_container) list = + [ ("deque", Deque) + ; ("list", List) + ; ("map", Map) + ; ("multimap", Multimap) + ; ("multiset", Multiset) + ; ("set", Set) + ; ("unordered_map", UnorderedMap) + ; ("unordered_multimap", UnorderedMultimap) + ; ("unordered_multiset", UnorderedMultiset) + ; ("unordered_set", UnorderedSet) ] + + +(* like the name matchers of [ProcnameDispatcher], ignore the template arguments that the frontend + appends to some names *) +let strip_template_args name = String.lsplit2 name ~on:'<' |> Option.value_map ~f:fst ~default:name + +let is_iterator name = List.mem iterators (strip_template_args name) ~equal:String.equal + +let container_of_name name = + List.Assoc.find containers ~equal:String.equal (strip_template_args name) + + +let class_name (name : Typ.Name.t) = + match name with + | CppClass {name} -> + QualifiedCppName.extract_last name + |> Option.map ~f:(fun (last, _) -> strip_template_args last) + | _ -> + None + + +let callee_class_name callee_procname = + Procname.get_class_type_name callee_procname |> Option.bind ~f:class_name + + +(** the iterator returned by a call whose last argument is [ret], directly or as the [first] field + of a [std::pair] *) +let returned_iterator path location event (ret : _ FuncArg.t option) astate = + let is_iterator_typ (typ : Typ.t) = + match typ.desc with + | Tstruct name -> + Option.exists (class_name name) ~f:is_iterator + | _ -> + false + in + match ret with + | Some {arg_payload= ret; typ= {desc= Tptr (typ, _)}} when is_iterator_typ typ -> + Some (Ok (astate, ret)) + | Some + { arg_payload= ret + ; typ= + { desc= + Tptr + ( { desc= + Tstruct + (CppClass {template_spec_info= Template {args= TType iter_typ :: _}} as pair) + } + , _ ) } } + when Option.exists (class_name pair) ~f:(String.equal "pair") && is_iterator_typ iter_typ -> + Some + (let* astate = + PulseOperations.write_deref_field path location ~ref:ret (Fieldname.make pair "second") + ~obj:(AbstractValue.mk_fresh (), Hist.single_event event) + astate + in + PulseOperations.eval_access path Read location ret + (FieldAccess (Fieldname.make pair "first")) + astate ) + | _ -> + None + + +(** insertions into a [std::deque] invalidate all its iterators; references to its elements are not + invalidated, which is only right for insertions at either end *) +let deque_insertion deque_f ~ret ~desc this args : model_no_non_disj = + fun {path; location; ret= ret_id, _} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + let astate = + PulseOperations.invalidate_deref_access path location + (StdContainer (Deque, deque_f)) + this (FieldAccess token_field) astate + in + let=* astate = + PulseOperations.havoc_deref_field path location this token_field (Hist.single_event event) + astate + in + let** astate = set_size_positive path location event this astate in + match ret with + | `Reference -> + let=+ astate, (elem, hist) = fresh_element path location this astate in + Ok (PulseOperations.write_id ret_id (elem, Hist.add_event event hist) astate) + | `Iterator -> ( + match returned_iterator path location event (List.last args) astate with + | Some result -> + let=* astate, ret_iter = result in + let=* astate, elem = fresh_element path location this astate in + Sat (make_iterator ~has_token:true path location event this ret_iter elem astate) + | None -> + Sat (Ok astate) ) + | `Nothing -> + Sat (Ok astate) + in + astate + + +(** insertions into a node-based container invalidate nothing; one that returns an iterator inserts + an element, or finds an equal one *) +let node_insertion ~desc this args : model_no_non_disj = + fun {path; location} astate -> + let event = Hist.call_event path location desc in + let<++> astate = + match returned_iterator path location event (List.last args) astate with + | Some result -> + let=* astate, ret_iter = result in + let=* astate, elem = fresh_element path location this astate in + let=* astate = + make_iterator ~has_token:false path location event this ret_iter elem astate + in + set_size_positive path location event this astate + | None -> + let=* astate = + PulseOperations.havoc_deref_field path location this Collection.size_field + (Hist.single_event event) astate + in + Sat (Ok astate) + in + astate + + +let callee_desc callee_procname class_name = + desc class_name (strip_template_args (Procname.get_method callee_procname)) + + +let on_iterator model : model_no_non_disj = + fun ({callee_procname} as model_data) astate -> + let iterator = callee_class_name callee_procname |> Option.value ~default:"" in + model + ~has_token:(String.equal iterator "__deque_iterator") + ~desc:(callee_desc callee_procname iterator) + model_data astate + + +let on_container model : model_no_non_disj = + fun ({callee_procname} as model_data) astate -> + let class_name = callee_class_name callee_procname |> Option.value ~default:"" in + match container_of_name class_name with + | Some container -> + model container ~desc:(callee_desc callee_procname class_name) model_data astate + | None -> + Logging.die InternalError "%a is not a method of a modelled container" Procname.pp + callee_procname + + +let matchers : matcher list = + let open ProcnameDispatcher.Call in + let iterator_typs () = List.map iterators ~f:(fun iterator -> -"std" &:: iterator) in + let is_iterator _ name = is_iterator name in + let is_container ?(f = fun _ -> true) _ name = Option.exists (container_of_name name) ~f in + let iterator_method name = -"std" &::+ is_iterator &:: name in + let iterator_matchers = + [ ( -"std" &::+ is_iterator &::+ is_iterator $ capt_arg_payload + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $--> fun this other -> on_iterator (Iterator.constructor this other) ) + ; ( iterator_method "operator=" <>$ capt_arg_payload $+ capt_arg_payload + $--> fun this other -> on_iterator (Iterator.operator_assign this other) ) + ; ( iterator_method "operator*" <>$ capt_arg_payload + $--> fun iter -> on_iterator (Iterator.operator_star iter) ) + ; ( iterator_method "operator->" <>$ capt_arg_payload + $--> fun iter -> on_iterator (Iterator.operator_star iter) ) + ; ( iterator_method "operator++" <>$ capt_arg_payload + $--> fun iter -> on_iterator (Iterator.operator_step `PlusPlus iter) ) + ; ( iterator_method "operator++" <>$ capt_arg_payload $+ any_arg $+ capt_arg_payload + $--> fun iter ret_iter -> on_iterator (Iterator.operator_step_postfix `PlusPlus iter ret_iter) + ) + ; ( iterator_method "operator--" <>$ capt_arg_payload + $--> fun iter -> on_iterator (Iterator.operator_step `MinusMinus iter) ) + ; ( iterator_method "operator--" <>$ capt_arg_payload $+ any_arg $+ capt_arg_payload + $--> fun iter ret_iter -> + on_iterator (Iterator.operator_step_postfix `MinusMinus iter ret_iter) ) ] + in + let comparison_matchers = + [ -"std" &:: "operator==" + $ capt_arg_payload_of_typ_exists (iterator_typs ()) + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $--> Iterator.operator_compare `Equal ~desc:"iterator operator==" + ; -"std" &:: "operator!=" + $ capt_arg_payload_of_typ_exists (iterator_typs ()) + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $--> Iterator.operator_compare `NotEqual ~desc:"iterator operator!=" ] + in + let container_method ?f name = -"std" &::+ is_container ?f &:: name in + let returns_iterator name model = + container_method name <>$ capt_arg_payload + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $--> fun this iter -> on_container (model this iter) + in + let is_node_based : Invalidation.std_container -> bool = function Deque -> false | _ -> true in + let container_matchers = + [ ( -"std" &::+ is_container &::+ is_container <>$ capt_arg_payload + $--> fun this -> on_container (fun _ ~desc -> Collection.default_constructor ~desc this) ) + ; returns_iterator "begin" begin_or_find + ; returns_iterator "cbegin" begin_or_find + ; returns_iterator "end" end_ + ; returns_iterator "cend" end_ + ; ( container_method "erase" <>$ capt_arg_payload + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $+ capt_arg_payload + $--> fun this pos ret_iter -> on_container (erase this pos ret_iter) ) + ; ( container_method ~f:is_node_based "insert" + $ capt_arg_payload + $++$--> fun this args -> on_container (fun _ ~desc -> node_insertion ~desc this args) ) + ; (container_method "clear" <>$ capt_arg_payload $--> fun this -> on_container (clear this)) + ; ( container_method "empty" <>$ capt_arg_payload + $--> fun this -> on_container (fun _ ~desc -> Collection.empty ~desc this) ) + ; ( container_method "size" <>$ capt_arg_payload + $--> fun this -> on_container (fun _ ~desc -> Collection.size ~desc this) ) ] + in + let is_associative : Invalidation.std_container -> bool = function + | Deque | List -> + false + | Map + | Multimap + | Multiset + | Set + | UnorderedMap + | UnorderedMultimap + | UnorderedMultiset + | UnorderedSet -> + true + in + let lookup_matchers = + [ ( container_method ~f:is_associative "find" + $ capt_arg_payload $+ any_arg + $+ capt_arg_payload_of_typ_exists (iterator_typs ()) + $--> fun this iter -> on_container (begin_or_find this iter) ) + ; ( container_method ~f:is_associative "count" + $ capt_arg_payload $+ any_arg + $--> fun this -> on_container (fun _ ~desc -> count ~desc this) ) + ; ( container_method ~f:is_associative "contains" + $ capt_arg_payload $+ any_arg + $--> fun this -> on_container (fun _ ~desc -> count ~desc this) ) ] + in + let is_sequence container = not (is_associative container) in + let front_back_matchers = + [ ( container_method ~f:is_sequence "front" + <>$ capt_arg_payload + $--> fun this -> on_container (fun _ ~desc -> element_reference ~desc this) ) + ; ( container_method ~f:is_sequence "back" + <>$ capt_arg_payload + $--> fun this -> on_container (fun _ ~desc -> element_reference ~desc this) ) ] + in + let is_map : Invalidation.std_container -> bool = function + | Map | UnorderedMap -> + true + | _ -> + false + in + let map_matchers = + [ ( container_method ~f:is_map "operator[]" + <>$ capt_arg_payload $+ any_arg + $--> fun this -> on_container (fun _ ~desc -> mapped_value_reference ~inserts:true ~desc this) + ) + ; ( container_method ~f:is_map "at" <>$ capt_arg_payload $+ any_arg + $--> fun this -> + on_container (fun _ ~desc -> mapped_value_reference ~inserts:false ~desc this) ) ] + in + let deque_desc = desc "deque" in + let deque_matchers = + [ -"std" &:: "deque" &:: "operator[]" <>$ capt_arg_payload $+ capt_arg_payload + $--> PulseModelsCpp.Vector.at ~desc:(deque_desc "operator[]") + ; -"std" &:: "deque" &:: "at" <>$ capt_arg_payload $+ capt_arg_payload + $--> PulseModelsCpp.Vector.at ~desc:(deque_desc "at") + ; -"std" &:: "deque" &:: "push_back" <>$ capt_arg_payload + $++$--> deque_insertion PushBack ~ret:`Nothing ~desc:(deque_desc "push_back") + ; -"std" &:: "deque" &:: "push_front" <>$ capt_arg_payload + $++$--> deque_insertion PushFront ~ret:`Nothing ~desc:(deque_desc "push_front") + ; -"std" &:: "deque" &:: "emplace_back" $ capt_arg_payload + $++$--> deque_insertion EmplaceBack ~ret:`Reference ~desc:(deque_desc "emplace_back") + ; -"std" &:: "deque" &:: "emplace_front" $ capt_arg_payload + $++$--> deque_insertion EmplaceFront ~ret:`Reference ~desc:(deque_desc "emplace_front") + ; -"std" &:: "deque" &:: "insert" $ capt_arg_payload + $++$--> deque_insertion Insert ~ret:`Iterator ~desc:(deque_desc "insert") + ; -"std" &:: "deque" &:: "emplace" $ capt_arg_payload + $++$--> deque_insertion Emplace ~ret:`Iterator ~desc:(deque_desc "emplace") ] + in + iterator_matchers @ comparison_matchers @ container_matchers @ lookup_matchers + @ front_back_matchers @ map_matchers @ deque_matchers + |> List.map ~f:(ProcnameDispatcher.Call.contramap_arg_payload ~f:ValueOrigin.addr_hist) + |> List.map ~f:(ProcnameDispatcher.Call.map_matcher ~f:lift_model) diff --git a/infer/src/pulse/PulseModelsStdContainers.mli b/infer/src/pulse/PulseModelsStdContainers.mli new file mode 100644 index 0000000000..b5e1b0f2fe --- /dev/null +++ b/infer/src/pulse/PulseModelsStdContainers.mli @@ -0,0 +1,11 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd +open PulseModelsImport + +val matchers : matcher list diff --git a/infer/src/pulse/PulseOperations.ml b/infer/src/pulse/PulseOperations.ml index 9013907dbe..a108f82a3b 100644 --- a/infer/src/pulse/PulseOperations.ml +++ b/infer/src/pulse/PulseOperations.ml @@ -19,6 +19,32 @@ let check_addr_access path ?must_be_valid_reason access_mode location (address, let* astate = AddressAttributes.check_valid path ?must_be_valid_reason access_trace address astate |> Result.map_error ~f:(fun (invalidation, invalidation_trace) -> + let astate = + match (invalidation : Invalidation.t) with + | (ComparedToNullInThisProcedure _ | ConstantDereference _) + when AbductiveDomain.is_read_from_pre_cell astate (address, history) -> + (* these only say that the address is null or another constant: for a pointer read + from the pre-condition, this is an assumption on the caller's value, so record that + it must be valid as [check_valid] does on successful accesses. All the null values + of a path share one canonical address, hence the check on the pointer's history. *) + AddressAttributes.abduce_one address + (MustBeValid (path.PathContext.timestamp, access_trace, must_be_valid_reason)) + astate + | ComparedToNullInThisProcedure _ + | ConstantDereference _ + | CFree + | CppDelete + | CppDeleteArray + | EndIterator + | FClose + | GoneOutOfScope _ + | OptionalEmpty + | StdVector _ + | StdString _ + | CppMap _ + | StdContainer _ -> + astate + in ReportableError { diagnostic= Diagnostic.AccessToInvalidAddress diff --git a/infer/src/pulse/PulseReport.ml b/infer/src/pulse/PulseReport.ml index b08a70c1a9..4f54f0bfa7 100644 --- a/infer/src/pulse/PulseReport.ml +++ b/infer/src/pulse/PulseReport.ml @@ -222,7 +222,9 @@ let is_constant_deref_without_invalidation (invalidation : Invalidation.t) acces | GoneOutOfScope _ | OptionalEmpty | StdVector _ - | CppMap _ -> + | StdString _ + | CppMap _ + | StdContainer _ -> false in if res then diff --git a/infer/src/pulse/PulseTaintOperations.ml b/infer/src/pulse/PulseTaintOperations.ml index 6522d8716a..6f3ec29fac 100644 --- a/infer/src/pulse/PulseTaintOperations.ml +++ b/infer/src/pulse/PulseTaintOperations.ml @@ -757,7 +757,18 @@ let pulse_models_to_treat_as_unknown_for_taint = ; ProcedureNameRegex { name_regex= Str.regexp "std::basic_string<.*>::basic_string" ; exclude_in= None - ; exclude_names= None } ] + ; exclude_names= None } + ; (* the mutators of [std::basic_string] are only modelled to invalidate the string's buffer *) + (let mutators = + List.map Invalidation.all_std_string_functions ~f:(fun string_f -> + Invalidation.std_string_method_name string_f |> Str.quote ) + |> String.concat ~sep:"\\|" + in + ProcedureNameRegex + { name_regex= + Str.regexp (Printf.sprintf "^std::basic_string<.*>::\\(%s\\)\\(<.*>\\)?$" mutators) + ; exclude_in= None + ; exclude_names= None } ) ] |> List.map ~f:dummy_matcher_of_procedure_matcher diff --git a/infer/tests/codetoanalyze/c/pulse/compared_to_null.c b/infer/tests/codetoanalyze/c/pulse/compared_to_null.c new file mode 100644 index 0000000000..a63d46fc51 --- /dev/null +++ b/infer/tests/codetoanalyze/c/pulse/compared_to_null.c @@ -0,0 +1,268 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include + +struct node { + int data; + struct node* next; +}; + +void log_message(const char* msg); + +// the null branch falls through to the dereference: reported as +// COMPARED_TO_NULL_AND_DEREFERENCED here and as NULLPTR_DEREFERENCE in callers +// that pass null +int get_data_compared_to_null_bad(struct node* n) { + if (n == NULL) { + log_message("null node"); + } + return n->data; +} + +int call_get_data_compared_to_null_with_null_bad() { + return get_data_compared_to_null_bad(NULL); +} + +int call_get_data_compared_to_null_ok() { + struct node n = {42, NULL}; + return get_data_compared_to_null_bad(&n); +} + +int wrap_get_data_compared_to_null(struct node* n) { + return get_data_compared_to_null_bad(n); +} + +int call_wrap_get_data_compared_to_null_with_null_bad() { + return wrap_get_data_compared_to_null(NULL); +} + +int check_then_get_data_compared_to_null_bad(struct node* n) { + if (n == NULL) { + log_message("null node"); + } + return get_data_compared_to_null_bad(n); +} + +int call_check_then_get_data_compared_to_null_with_null_bad() { + return check_then_get_data_compared_to_null_bad(NULL); +} + +int get_data_compared_to_null_else_bad(struct node* n) { + if (n != NULL) { + log_message("non-null node"); + } else { + log_message("null node"); + } + return n->data; +} + +int call_get_data_compared_to_null_else_with_null_bad() { + return get_data_compared_to_null_else_bad(NULL); +} + +int get_next_data_compared_to_null_bad(struct node* n) { + struct node* next = n->next; + if (next == NULL) { + log_message("no next node"); + } + return next->data; +} + +int call_get_next_data_compared_to_null_with_null_bad() { + struct node n = {42, NULL}; + return get_next_data_compared_to_null_bad(&n); +} + +size_t length_compared_to_null_bad(const char* s) { + if (s == NULL) { + log_message("null string"); + } + return strlen(s); +} + +size_t call_length_compared_to_null_with_null_bad() { + return length_compared_to_null_bad(NULL); +} + +int is_zero(int x) { return x == 0; } + +// the error is latent here because it depends on the result of [is_zero] +int get_data_compared_to_null_if_zero_bad(struct node* n, int x) { + if (is_zero(x)) { + if (n == NULL) { + log_message("null node"); + } + return n->data; + } + return 0; +} + +int call_get_data_compared_to_null_if_zero_with_null_bad() { + return get_data_compared_to_null_if_zero_bad(NULL, 0); +} + +int call_get_data_compared_to_null_if_zero_with_null_ok() { + return get_data_compared_to_null_if_zero_bad(NULL, 1); +} + +// [!n] does not count as a comparison to null so only callers are reported +int get_data_negated_check(struct node* n) { + if (!n) { + log_message("null node"); + } + return n->data; +} + +int call_get_data_negated_check_with_null_bad() { + return get_data_negated_check(NULL); +} + +int get_data_compared_to_null_local_bad(struct node* n) { + struct node* empty = NULL; + if (n == empty) { + log_message("null node"); + } + return n->data; +} + +int call_get_data_compared_to_null_local_with_null_bad() { + return get_data_compared_to_null_local_bad(NULL); +} + +int last_data; + +// Pulse identifies [n] with the constant 0 written in the null branch, which +// makes [n] itself an invalid address +int get_data_negated_check_reset_bad(struct node* n) { + if (!n) { + last_data = 0; + } + return n->data; +} + +int call_get_data_negated_check_reset_with_null_bad() { + return get_data_negated_check_reset_bad(NULL); +} + +int get_data_or_default_ok(struct node* n) { + if (n == NULL) { + return -1; + } + return n->data; +} + +int call_get_data_or_default_with_null_ok() { + return get_data_or_default_ok(NULL); +} + +int get_data_or_abort_ok(struct node* n) { + if (n == NULL) { + abort(); + } + return n->data; +} + +int call_get_data_or_abort_with_null_ok() { return get_data_or_abort_ok(NULL); } + +void fatal_error(const char* msg); + +// [fatal_error] does not return but Infer cannot know it without a definition +// or a noreturn attribute, so the null branch reaches the dereference (same +// with [!n]) +int FP_get_data_compared_to_null_or_fatal_ok(struct node* n) { + if (n == NULL) { + fatal_error("null node"); + } + return n->data; +} + +int FP_call_get_data_compared_to_null_or_fatal_with_null_ok() { + return FP_get_data_compared_to_null_or_fatal_ok(NULL); +} + +struct node* same_node(struct node* n) { return n; } + +int get_data_of_same_node_bad(struct node* n) { + struct node* m = same_node(n); + if (n == NULL) { + log_message("null node"); + } + return m->data; +} + +int call_get_data_of_same_node_with_null_bad() { + return get_data_of_same_node_bad(NULL); +} + +// on the path where [n] is null, [m] is null too and Pulse identifies them, +// but the null dereference does not depend on the caller: it is only reported +// here +int get_data_of_null_local_bad(struct node* n) { + struct node* m = NULL; + if (n == NULL) { + log_message("null node"); + } + return m->data; +} + +int call_get_data_of_null_local_with_null_ok() { + return get_data_of_null_local_bad(NULL); +} + +struct node* lookup(struct node* key); + +// the result of an unknown call does not come from the caller, even when the +// caller passes null to the call +int get_data_of_lookup_bad(struct node* n) { + if (n == NULL) { + log_message("null node"); + } + struct node* m = lookup(n); + if (m == NULL) { + log_message("not found"); + } + return m->data; +} + +int call_get_data_of_lookup_with_null_ok() { + return get_data_of_lookup_bad(NULL); +} + +struct node* lookup_wrapper(struct node* key) { return lookup(key); } + +int get_data_of_lookup_wrapper_bad(struct node* n) { + if (n == NULL) { + log_message("null node"); + } + struct node* m = lookup_wrapper(n); + if (m == NULL) { + log_message("not found"); + } + return m->data; +} + +int call_get_data_of_lookup_wrapper_with_null_ok() { + return get_data_of_lookup_wrapper_bad(NULL); +} + +char* get_buffer(size_t size); + +int fill_buffer_bad(size_t len) { + if (len == 0) { + log_message("empty buffer"); + } + char* buf = get_buffer(len + 1); + if (buf == NULL) { + log_message("out of memory"); + } + buf[0] = 'a'; + return 0; +} + +int call_fill_buffer_with_zero_ok() { return fill_buffer_bad(0); } diff --git a/infer/tests/codetoanalyze/c/pulse/issues.exp b/infer/tests/codetoanalyze/c/pulse/issues.exp index 6025fe94ac..b53429528e 100644 --- a/infer/tests/codetoanalyze/c/pulse/issues.exp +++ b/infer/tests/codetoanalyze/c/pulse/issues.exp @@ -24,6 +24,35 @@ codetoanalyze/c/pulse/cleanup_attribute.c, cleanup_in_statement_expression_bad, codetoanalyze/c/pulse/cleanup_attribute.c, cleanup_in_returned_statement_expression_bad, 5, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,allocated by call to `malloc` (modelled),assigned,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,allocated by call to `malloc` (modelled),assigned,when calling `cleanup_int` here,parameter `x` of cleanup_int,invalid access occurs here] codetoanalyze/c/pulse/cleanup_attribute.c, cleanup_goto_out_of_scope_bad, 5, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,allocated by call to `malloc` (modelled),assigned,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,allocated by call to `malloc` (modelled),assigned,when calling `cleanup_int` here,parameter `x` of cleanup_int,invalid access occurs here] codetoanalyze/c/pulse/cleanup_attribute.c, cleanup_goto_backward_past_declaration_bad, 6, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,allocated by call to `malloc` (modelled),assigned,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,allocated by call to `malloc` (modelled),assigned,when calling `cleanup_int` here,parameter `x` of cleanup_int,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_compared_to_null_bad, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_data_compared_to_null_bad,was compared to null on line 22, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_compared_to_null_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_compared_to_null_bad` here,parameter `n` of get_data_compared_to_null_bad,was compared to null on line 22, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_wrap_get_data_compared_to_null_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `wrap_get_data_compared_to_null` here,parameter `n` of wrap_get_data_compared_to_null,when calling `get_data_compared_to_null_bad` here,parameter `n` of get_data_compared_to_null_bad,was compared to null on line 22, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, check_then_get_data_compared_to_null_bad, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of check_then_get_data_compared_to_null_bad,was compared to null on line 46, column 7,when calling `get_data_compared_to_null_bad` here,parameter `n` of get_data_compared_to_null_bad,was compared to null on line 22, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_check_then_get_data_compared_to_null_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `check_then_get_data_compared_to_null_bad` here,parameter `n` of check_then_get_data_compared_to_null_bad,was compared to null on line 46, column 7,when calling `get_data_compared_to_null_bad` here,parameter `n` of get_data_compared_to_null_bad,was compared to null on line 22, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_compared_to_null_else_bad, 6, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_data_compared_to_null_else_bad,was compared to null on line 57, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_compared_to_null_else_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_compared_to_null_else_bad` here,parameter `n` of get_data_compared_to_null_else_bad,was compared to null on line 57, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_next_data_compared_to_null_bad, 5, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_next_data_compared_to_null_bad,assigned,was compared to null on line 71, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_next_data_compared_to_null_with_null_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,when calling `get_next_data_compared_to_null_bad` here,parameter `n` of get_next_data_compared_to_null_bad,assigned,was compared to null on line 71, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, length_compared_to_null_bad, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `s` of length_compared_to_null_bad,was compared to null on line 83, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_length_compared_to_null_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `length_compared_to_null_bad` here,parameter `s` of length_compared_to_null_bad,was compared to null on line 83, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_compared_to_null_if_zero_bad, 5, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_data_compared_to_null_if_zero_bad,was compared to null on line 98, column 9,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_compared_to_null_if_zero_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_compared_to_null_if_zero_bad` here,parameter `n` of get_data_compared_to_null_if_zero_bad,was compared to null on line 98, column 9,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_negated_check_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_negated_check` here,parameter `n` of get_data_negated_check,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_compared_to_null_local_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [*** SUPPRESSED ***,source of the null value part of the trace starts here,assigned,is assigned to the null pointer,null pointer dereference part of the trace starts here,parameter `n` of get_data_compared_to_null_local_bad,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_compared_to_null_local_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_compared_to_null_local_bad` here,parameter `n` of get_data_compared_to_null_local_bad,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_negated_check_reset_bad, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [*** SUPPRESSED ***,source of the null value part of the trace starts here,assigned,is assigned to the null pointer,null pointer dereference part of the trace starts here,parameter `n` of get_data_negated_check_reset_bad,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_negated_check_reset_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_negated_check_reset_bad` here,parameter `n` of get_data_negated_check_reset_bad,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, FP_get_data_compared_to_null_or_fatal_ok, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of FP_get_data_compared_to_null_or_fatal_ok,was compared to null on line 179, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, FP_call_get_data_compared_to_null_or_fatal_with_null_ok, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `FP_get_data_compared_to_null_or_fatal_ok` here,parameter `n` of FP_get_data_compared_to_null_or_fatal_ok,was compared to null on line 179, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_same_node_bad, 5, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [*** SUPPRESSED ***,compared to null here,parameter `n` of get_data_of_same_node_bad,in call to `same_node`,parameter `n` of same_node,returned,return from call to `same_node`,assigned,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, call_get_data_of_same_node_with_null_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `get_data_of_same_node_bad` here,parameter `n` of get_data_of_same_node_bad,in call to `same_node`,parameter `n` of same_node,returned,return from call to `same_node`,assigned,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_null_local_bad, 5, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [*** SUPPRESSED ***,compared to null here,is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_null_local_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_lookup_bad, 8, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,in call to function `lookup` with no summary,assigned,was compared to null on line 227, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_lookup_bad, 8, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,in call to function `lookup` with no summary,assigned,was compared to null on line 227, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_lookup_wrapper_bad, 8, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_data_of_lookup_wrapper_bad,was compared to null on line 240, column 7,in call to `lookup_wrapper`,in call to function `lookup` with no summary,returned,return from call to `lookup_wrapper`,assigned,was compared to null on line 244, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, get_data_of_lookup_wrapper_bad, 8, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `n` of get_data_of_lookup_wrapper_bad,in call to `lookup_wrapper`,in call to function `lookup` with no summary,returned,return from call to `lookup_wrapper`,assigned,was compared to null on line 244, column 7,invalid access occurs here] +codetoanalyze/c/pulse/compared_to_null.c, fill_buffer_bad, 8, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,in call to function `get_buffer` with no summary,assigned,was compared to null on line 261, column 7,invalid access occurs here] codetoanalyze/c/pulse/compound_literal.c, detect_zero_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/c/pulse/dangling_deref.c, dangling_deref_bad, 3, PULSE_UNINITIALIZED_VALUE, no_bucket, ERROR, [variable `y` declared here,read to uninitialized value occurs here] codetoanalyze/c/pulse/dangling_deref.c, intraproc_dangling_deref_bad, 3, PULSE_UNINITIALIZED_VALUE, no_bucket, ERROR, [variable `y` declared here,read to uninitialized value occurs here] diff --git a/infer/tests/codetoanalyze/cpp/impurity/issues.exp b/infer/tests/codetoanalyze/cpp/impurity/issues.exp index e2c478667a..749d97e3e6 100644 --- a/infer/tests/codetoanalyze/cpp/impurity/issues.exp +++ b/infer/tests/codetoanalyze/cpp/impurity/issues.exp @@ -24,11 +24,14 @@ codetoanalyze/cpp/impurity/invalid_test.cpp, swap_address_impure, 0, IMPURE_FUNC codetoanalyze/cpp/impurity/param_test.cpp, modify_mut_ref_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function modify_mut_ref_impure,parameter `x.*` modified here] codetoanalyze/cpp/impurity/param_test.cpp, create_cycle_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function create_cycle_impure,parameter `x.*next` modified here] codetoanalyze/cpp/impurity/param_test.cpp, invalidate_local_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function invalidate_local_impure,parameter `pp.*` modified here] +codetoanalyze/cpp/impurity/std_containers.cpp, map_erase_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function map_erase_impure,parameter `map.*__infer_size` modified here,parameter `map.*__infer_backing_array*[]` was invalidated by `std::map::erase` here] +codetoanalyze/cpp/impurity/std_containers.cpp, list_write_elements_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function list_write_elements_impure,parameter `list.*__infer_backing_array*[]` modified here] +codetoanalyze/cpp/impurity/std_containers.cpp, map_write_found_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function map_write_found_impure,parameter `map.*__infer_backing_array*[]second` modified here] codetoanalyze/cpp/impurity/unmodeled.cpp, output_stream_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function output_stream_impure,global variable `std::cout.*` modified here,call to skipped function std::basic_ostream>::operator<< occurs here,call to skipped function std::operator<<_> occurs here] codetoanalyze/cpp/impurity/unmodeled.cpp, random_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function random_impure,call to skipped function rand occurs here] -codetoanalyze/cpp/impurity/vector.cpp, insert_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function insert_impure,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] +codetoanalyze/cpp/impurity/vector.cpp, insert_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function insert_impure,parameter `vec.*__infer_size` modified here,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] codetoanalyze/cpp/impurity/vector.cpp, push_back_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function push_back_impure,parameter `vec.*__infer_size` modified here,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] codetoanalyze/cpp/impurity/vector.cpp, push_back_in_loop_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function push_back_in_loop_impure,parameter `vec.*__infer_size` modified here,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] codetoanalyze/cpp/impurity/vector.cpp, clear_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function clear_impure,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] -codetoanalyze/cpp/impurity/vector.cpp, assign_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function assign_impure,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] +codetoanalyze/cpp/impurity/vector.cpp, assign_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function assign_impure,parameter `vec.*__infer_size` modified here,parameter `vec.*__infer_backing_array` modified here,parameter `vec.*` modified here] codetoanalyze/cpp/impurity/vector.cpp, set_zero_impure, 0, IMPURE_FUNCTION, no_bucket, ERROR, [Impure function set_zero_impure,parameter `numbers.*__infer_backing_array*[]i` modified here] diff --git a/infer/tests/codetoanalyze/cpp/impurity/std_containers.cpp b/infer/tests/codetoanalyze/cpp/impurity/std_containers.cpp new file mode 100644 index 0000000000..6e80ba3373 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/impurity/std_containers.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include +#include + +int map_iterate_pure(const std::map& map) { + int sum = 0; + for (const auto& entry : map) { + sum += entry.second; + } + return sum; +} + +int map_find_pure(const std::map& map) { + auto it = map.find(1); + return it == map.end() ? 0 : it->second; +} + +void map_erase_impure(std::map& map) { map.erase(map.begin()); } + +void list_write_elements_impure(std::list& list) { + for (auto& x : list) { + x = 0; + } +} + +void map_write_found_impure(std::map& map) { + auto it = map.find(1); + if (it != map.end()) { + it->second = 2; + } +} diff --git a/infer/tests/codetoanalyze/cpp/pulse-17/issues.exp b/infer/tests/codetoanalyze/cpp/pulse-17/issues.exp index 229372a680..2239e8a87f 100644 --- a/infer/tests/codetoanalyze/cpp/pulse-17/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse-17/issues.exp @@ -50,6 +50,16 @@ codetoanalyze/cpp/pulse-17/std_optional.cpp, std_operator_arrow_bad, 0, OPTIONAL codetoanalyze/cpp/pulse-17/std_optional.cpp, might_return_none, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter x with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse-17/std_optional.cpp, FP_cannot_be_empty, 2, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `getOptionalValue`,in call to `std::optional::optional(=nullopt)` (modelled),is assigned an empty value,return from call to `getOptionalValue`,invalid access occurs here] codetoanalyze/cpp/pulse-17/std_optional.cpp, inside_try_catch_FP, 3, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `might_return_none`,in call to `std::optional::optional(=nullopt)` (modelled),is assigned an empty value,return from call to `might_return_none`,invalid access occurs here] +codetoanalyze/cpp/pulse-17/std_vector.cpp, deref_emplace_back_result_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `std::vector::emplace_back()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,in call to `std::vector::emplace_back()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse-17/std_vector.cpp, deref_emplace_back_no_args_result_after_push_back_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `std::vector::emplace_back()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,in call to `std::vector::emplace_back()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_of_temporary_string_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::operator_basic_string_view()` (modelled),in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_outlives_string_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::operator_basic_string_view()` (modelled),in call to `std::basic_string_view::operator=()` (modelled),in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::copy_of_view_outlives_string_bad, 8, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::operator_basic_string_view()` (modelled),in call to `std::basic_string_view::basic_string_view()` (modelled),in call to `std::basic_string_view::data()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_returned_from_callee_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `string_view::view_of`,parameter `s` of string_view::view_of,return from call to `string_view::view_of`,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `string_view::view_of`,parameter `s` of string_view::view_of,in call to `std::basic_string::operator_basic_string_view()` (modelled),return from call to `string_view::view_of`,in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::pass_view_of_destroyed_string_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::operator_basic_string_view()` (modelled),in call to `std::basic_string_view::operator=()` (modelled),in call to `std::basic_string_view::basic_string_view()` (modelled),when calling `string_view::deref_view` here,parameter `sv` of string_view::deref_view,in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_of_string_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of string_view::view_of_string_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of string_view::view_of_string_then_append_bad,in call to `std::basic_string::operator_basic_string_view()` (modelled),in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_of_freed_buffer_bad, 8, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,allocated by call to `malloc` (modelled),assigned,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,allocated by call to `malloc` (modelled),assigned,in call to `std::basic_string_view::basic_string_view()` (modelled),in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse-17/string_view.cpp, string_view::view_with_size_of_deleted_array_bad, 5, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,allocated by call to `new[]` (modelled),assigned,was invalidated by `delete[]`,use-after-lifetime part of the trace starts here,allocated by call to `new[]` (modelled),assigned,in call to `std::basic_string_view::basic_string_view()` (modelled),in call to `std::basic_string_view::data()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse-17/unnecessary_copy.cpp, unnecessary_copy::call_get_optional_const_ref_bad, 2, PULSE_UNNECESSARY_COPY_OPTIONAL, no_bucket, ERROR, [copied by Optional value construction here (with type `unnecessary_copy::Arr&`)] codetoanalyze/cpp/pulse-17/unnecessary_copy.cpp, unnecessary_copy::call_get_optional_value_bad, 2, PULSE_UNNECESSARY_COPY_OPTIONAL, no_bucket, ERROR, [copied by Optional value construction here (with type `unnecessary_copy::Arr&`)] codetoanalyze/cpp/pulse-17/unnecessary_copy.cpp, unnecessary_copy::structured_binding_bad, 4, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::tuple&`)] diff --git a/infer/tests/codetoanalyze/cpp/pulse-17/std_vector.cpp b/infer/tests/codetoanalyze/cpp/pulse-17/std_vector.cpp new file mode 100644 index 0000000000..9b19fe077c --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse-17/std_vector.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include + +int deref_emplace_back_result_after_push_back_bad(std::vector& vec) { + int& elt = vec.emplace_back(7); + vec.push_back(42); + return elt; +} + +int deref_emplace_back_no_args_result_after_push_back_bad( + std::vector& vec) { + int& elt = vec.emplace_back(); + vec.push_back(42); + return elt; +} + +int deref_emplace_back_result_ok(std::vector& vec) { + int& elt = vec.emplace_back(7); + return elt; +} + +int reserve_then_emplace_back_result_ok(std::vector& vec) { + vec.reserve(vec.size() + 2); + int& elt = vec.emplace_back(7); + vec.emplace_back(8); + return elt; +} + +int emplace_back_results_are_distinct_ok(std::vector& vec, int x) { + vec.reserve(vec.size() + 2); + int*& first = vec.emplace_back(); + first = &x; + int*& second = vec.emplace_back(); + second = nullptr; + return *first; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse-17/string_view.cpp b/infer/tests/codetoanalyze/cpp/pulse-17/string_view.cpp new file mode 100644 index 0000000000..5d3befc685 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse-17/string_view.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include +#include +#include +#include + +namespace string_view { + +std::string make_string(); + +char view_of_temporary_string_bad() { + std::string_view sv = make_string(); + return *sv.data(); +} + +char view_outlives_string_bad() { + std::string_view sv; + { + std::string s = "blah"; + sv = s; + } + return *sv.data(); +} + +char copy_of_view_outlives_string_bad() { + const char* p; + { + std::string s = "blah"; + std::string_view sv = s; + std::string_view copy(sv); + p = copy.data(); + } + return *p; +} + +std::string_view view_of(const std::string& s) { return s; } + +char view_returned_from_callee_bad() { + std::string_view sv = view_of(make_string()); + return *sv.data(); +} + +char deref_view(std::string_view sv) { return *sv.data(); } + +char pass_view_of_destroyed_string_bad() { + std::string_view sv; + { + std::string s = "blah"; + sv = s; + } + return deref_view(sv); +} + +char pass_view_of_temporary_ok() { return deref_view(make_string()); } + +char view_of_string_then_append_bad(std::string& s) { + std::string_view sv = s; + s.append(1000, 'x'); + return *sv.data(); +} + +char view_of_freed_buffer_bad() { + char* buf = (char*)malloc(16); + if (buf == nullptr) { + return 0; + } + strcpy(buf, "abc"); + std::string_view sv(buf); + free(buf); + return *sv.data(); +} + +char view_with_size_of_deleted_array_bad() { + char* buf = new char[16]; + buf[0] = 'a'; + std::string_view sv(buf, 1); + delete[] buf; + return *sv.data(); +} + +void view_data_is_string_data_ok(const std::string& s) { + std::string_view sv = s; + if (s.data() != sv.data()) { + int* q = nullptr; + *q = 42; + } +} + +void view_data_is_char_ptr_ok(const char* p) { + std::string_view sv(p); + if (sv.data() != p) { + int* q = nullptr; + *q = 42; + } +} + +void view_with_size_data_is_char_ptr_ok(const char* p, size_t n) { + std::string_view sv(p, n); + std::string_view copy = sv; + if (copy.data() != p) { + int* q = nullptr; + *q = 42; + } +} + +char view_of_live_string_ok() { + std::string s = "blah"; + std::string_view sv = s; + std::string_view copy = sv; + return *copy.data(); +} + +char view_of_literal_ok() { + std::string_view sv = "abc"; + return *sv.data(); +} + +wchar_t wide_view_of_literal_ok() { + std::wstring_view sv = L"abc"; + return *sv.data(); +} + +void string_from_view_keeps_length_ok() { + std::string_view sv = "abc"; + std::string s(sv); + if (s.length() != 3) { + int* q = nullptr; + *q = 42; + } +} + +void string_from_view_with_size_keeps_length_ok(const char* p) { + std::string_view sv(p, 3); + std::string s(sv); + if (s.length() != 3) { + int* q = nullptr; + *q = 42; + } +} + +} // namespace string_view diff --git a/infer/tests/codetoanalyze/cpp/pulse/basic_string.cpp b/infer/tests/codetoanalyze/cpp/pulse/basic_string.cpp index 264913059d..12a080d999 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/basic_string.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/basic_string.cpp @@ -4,7 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +#include +#include +#include #include +#include // inspired by folly::Range struct Range { @@ -54,3 +58,284 @@ void copy_string_ok() { *p = 42; } } + +std::string make_string(); + +size_t c_str_of_temporary_bad() { + const char* p = make_string().c_str(); + return strlen(p); +} + +size_t c_str_of_temporary_in_full_expression_ok() { + return strlen(make_string().c_str()); +} + +size_t c_str_of_lifetime_extended_temporary_ok() { + const std::string& s = make_string(); + const char* p = s.c_str(); + return strlen(p); +} + +char c_str_after_scope_bad() { + const char* p; + { + std::string s("hello"); + p = s.c_str(); + } + return *p; +} + +const char* c_str_of_local() { + std::string s("hello"); + return s.c_str(); +} + +char use_c_str_of_local_bad() { return *c_str_of_local(); } + +char data_then_append_bad(std::string& s) { + const char* p = s.data(); + s.append(1000, 'x'); + return *p; +} + +char c_str_then_push_back_bad(std::string& s) { + const char* p = s.c_str(); + s.push_back('x'); + return *p; +} + +char c_str_then_plus_assign_bad(std::string& s) { + const char* p = s.c_str(); + s += "more"; + return *p; +} + +char c_str_then_assign_bad(std::string& s, const std::string& t) { + const char* p = s.c_str(); + s = t; + return *p; +} + +char c_str_then_clear_bad(std::string& s) { + const char* p = s.c_str(); + s.clear(); + return *p; +} + +char c_str_then_insert_bad(std::string& s) { + const char* p = s.c_str(); + s.insert(0, "more"); + return *p; +} + +char c_str_then_reserve_bad(std::string& s) { + const char* p = s.c_str(); + s.reserve(1000); + return *p; +} + +void append_to(std::string& s) { s.append(1000, 'x'); } + +char c_str_then_append_in_callee_bad(std::string& s) { + const char* p = s.c_str(); + append_to(s); + return *p; +} + +char c_str_then_erase_bad(std::string& s) { + const char* p = s.c_str(); + s.erase(0, 1); + return *p; +} + +char c_str_then_pop_back_bad(std::string& s) { + const char* p = s.c_str(); + s.pop_back(); + return *p; +} + +char c_str_after_reserve_then_append_bad(std::string& s) { + s.reserve(100); + const char* p = s.c_str(); + s += "abc"; + return *p; +} + +char c_str_of_append_result_then_push_back_bad(std::string& s) { + const char* p = s.append("b").c_str(); + s.push_back('c'); + return *p; +} + +char c_str_of_append_result_ok(std::string& s) { + const char* p = s.append("b").c_str(); + return *p; +} + +char c_str_after_append_ok(std::string& s) { + s.append(1000, 'x'); + const char* p = s.c_str(); + return *p; +} + +char c_str_then_const_calls_ok(const std::string& s) { + const char* p = s.c_str(); + if (s.empty() || s.length() == 0 || s.size() == 0) { + return 0; + } + return *p; +} + +char c_str_then_append_other_string_ok(std::string& s, std::string& t) { + const char* p = s.c_str(); + t.append("x"); + return *p; +} + +std::string copy_then_append_ok(const std::string& s) { + std::string t = s; + t.append("x"); + return t; +} + +char begin_then_append_bad(std::string& s) { + auto it = s.begin(); + s.append(1000, 'x'); + return *it; +} + +char begin_again_after_append_ok(std::string& s) { + auto it = s.begin(); + s.append(1000, 'x'); + it = s.begin(); + return *it; +} + +char find_then_append_bad(std::string& s) { + auto it = std::find(s.begin(), s.end(), 'a'); + s.append(1000, 'x'); + return *it; +} + +void erase_in_loop_ok(std::string& s) { + for (auto it = s.begin(); it != s.end();) { + if (*it == '\r') { + it = s.erase(it); + } else { + ++it; + } + } +} + +void insert_in_loop_ok(std::string& s) { + for (auto it = s.begin(); it != s.end(); ++it) { + if (*it == '\n') { + it = s.insert(it, '\r'); + ++it; + } + } +} + +char assigned_begin_after_scope_bad() { + std::string::iterator it; + { + std::string s("hello"); + it = s.begin(); + } + return *it; +} + +int sum_chars(const std::string& s) { + int n = 0; + for (char c : s) { + n += c; + } + return n; +} + +int iterate_copy_of_c_str_after_clear_ok(std::string& s) { + std::string t(s.c_str()); + s.clear(); + return sum_chars(t); +} + +int iterate_copy_of_data_after_scope_ok() { + std::string* t; + { + std::string s("hello"); + t = new std::string(s.data(), s.size()); + } + int n = sum_chars(*t); + delete t; + return n; +} + +// operator[] is not tied to the modelled buffer +char FN_subscript_then_append_bad(std::string& s) { + const char* p = &s[0]; + s.append(1000, 'x'); + return *p; +} + +// swap() is not modelled +char FN_c_str_then_swap_bad(std::string& s, std::string& t) { + const char* p = s.c_str(); + s.swap(t); + return *p; +} + +// swap() is not modelled +char FN_c_str_then_std_swap_bad(std::string& s, std::string& t) { + const char* p = s.c_str(); + std::swap(s, t); + return *p; +} + +// only the buffer of the assigned string is invalidated, not the one of the +// source +char FN_c_str_of_moved_from_string_bad(std::string& s, std::string& t) { + const char* p = t.c_str(); + s = std::move(t); + return *p; +} + +// only member functions of the string invalidate its buffer +char FN_c_str_then_getline_bad(std::string& s) { + const char* p = s.c_str(); + std::getline(std::cin, s); + return *p; +} + +// only member functions of the string invalidate its buffer +char FN_c_str_then_extract_bad(std::string& s) { + const char* p = s.c_str(); + std::cin >> s; + return *p; +} + +// the iterator returned by cbegin() is not tied to the buffer +char FN_cbegin_then_append_bad(std::string& s) { + auto it = s.cbegin(); + s.append(1000, 'x'); + return *it; +} + +// the iterator returned by end() is not tied to the buffer +char FN_end_then_reserve_bad(std::string& s) { + if (s.empty()) { + return 0; + } + auto it = s.end(); + s.reserve(100); + return *(it - 1); +} + +// pointer arithmetic loses the link to the buffer +char FN_data_plus_one_then_append_bad(std::string& s) { + if (s.size() < 2) { + return 0; + } + const char* p = s.data() + 1; + s.append(1000, 'x'); + return *p; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/const_refable.cpp b/infer/tests/codetoanalyze/cpp/pulse/const_refable.cpp index 9fa96fb844..8700e0ff9b 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/const_refable.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/const_refable.cpp @@ -72,6 +72,19 @@ int sum_in_loop_bad(std::vector vec) { return total; } +int sum_set_in_loop_bad(std::set set) { + int total = 0; + for (int x : set) { + total += x; + } + return total; +} + +int erase_first_ok(std::set set) { + set.erase(set.begin()); + return set.size(); +} + // anonymous parameters usually exist to satisfy the signature for virtual // functions. If we recommend const ref, the signature would not match and // making the base function const-refable might not be possible since it might @@ -203,6 +216,17 @@ void void_cast(std::string* s) { (void)s; } // FN because now infer_skip is addressed as an unknown call void call_void_cast_bad_FN(std::string s) { void_cast(&s); } +void read_chars(const char* p); + +void read_c_str_bad(std::string s) { read_chars(s.c_str()); } + +// [(void)p] is translated to an unknown call that is considered to write to +// what [p] points to +void void_cast_c_str_bad_FN(std::string s) { + const char* p = s.c_str(); + (void)p; +} + int get_lambda(const std::function& f, Arr a) { return f(std::move(a)); } diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp b/infer/tests/codetoanalyze/cpp/pulse/issues.exp index 998069af43..296fe2b59a 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp @@ -15,6 +15,24 @@ codetoanalyze/cpp/pulse/array_init.cpp, array_init::FP_constructor_filler_leak_o codetoanalyze/cpp/pulse/basic_string.cpp, use_range_of_invalidated_temporary_string_bad, 2, USE_AFTER_DELETE_LATENT, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `setLanguage` here,variable `C++ temporary` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `Range::Range`,parameter `str` of Range::Range,return from call to `Range::Range`,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,in call to `setLanguage`,variable `C++ temporary` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `Range::Range`,parameter `str` of Range::Range,in call to `std::basic_string::data()` (modelled),in call to `std::basic_string::data()` (modelled),assigned,return from call to `Range::Range`,return from call to `setLanguage`,when calling `Range::operator[]` here,parameter `this` of Range::operator[],invalid access occurs here] codetoanalyze/cpp/pulse/basic_string.cpp, copy_string_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/basic_string.cpp, copy_string_ok, 2, PULSE_UNNECESSARY_COPY, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_of_temporary_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_after_scope_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, use_c_str_of_local_bad, 0, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `c_str_of_local` here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,in call to `c_str_of_local`,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),returned,return from call to `c_str_of_local`,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, data_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of data_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of data_then_append_bad,in call to `std::basic_string::data()` (modelled),in call to `std::basic_string::data()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_push_back_bad,was potentially invalidated by `std::basic_string::push_back`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_push_back_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_plus_assign_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_plus_assign_bad,was potentially invalidated by `std::basic_string::operator+=`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_plus_assign_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_assign_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_assign_bad,was potentially invalidated by `std::basic_string::operator=`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_assign_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_clear_bad,was potentially invalidated by `std::basic_string::clear`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_clear_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_insert_bad,was potentially invalidated by `std::basic_string::insert`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_insert_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_reserve_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_reserve_bad,was potentially invalidated by `std::basic_string::reserve`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_reserve_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_append_in_callee_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_append_in_callee_bad,when calling `append_to` here,parameter `s` of append_to,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_append_in_callee_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_erase_bad,was potentially invalidated by `std::basic_string::erase`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_erase_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_pop_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_pop_back_bad,was potentially invalidated by `std::basic_string::pop_back`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_pop_back_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_after_reserve_then_append_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_after_reserve_then_append_bad,was potentially invalidated by `std::basic_string::operator+=`,use-after-lifetime part of the trace starts here,in call to function `std::basic_string,std::allocator>::reserve` with no summary,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_of_append_result_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_of_append_result_then_push_back_bad,was potentially invalidated by `std::basic_string::push_back`,use-after-lifetime part of the trace starts here,in call to function `std::basic_string,std::allocator>::append` with no summary,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, begin_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of begin_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of begin_then_append_bad,in call to `std::basic_string::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, find_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of find_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,variable `it` accessed here,in call to `std::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, assigned_begin_after_scope_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::begin()` (modelled),in call to `iterator operator=` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_branch_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_branch_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_loop_bad, 5, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_loop_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_loop_bad,invalid access occurs here] @@ -71,6 +89,7 @@ codetoanalyze/cpp/pulse/conditionals.cpp, binary_and_bad, 3, USE_AFTER_FREE, no_ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::read_first_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter a with type `const_refable::Arr`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::interprocedural_read_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::sum_in_loop_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] +codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::sum_set_in_loop_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter set with type `std::set,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::std_pair_vector_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter p with type `std::pair>>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::std_pair_string_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter p with type `std::pair,std::allocator>,std::basic_string,std::allocator>>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::folly_optional_vector_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec_opt with type `folly::Optional>>`] @@ -78,6 +97,7 @@ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::folly_optional_string_ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::havoc_reachable_by_unknown_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `const_refable::StructWithInt`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::AssignField::assign_field_bad, 0, PULSE_UNNECESSARY_COPY_ASSIGNMENT, no_bucket, ERROR, [copy assigned here (with type `const_refable::Arr&`)] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::AssignField::assign_global_bad, 0, PULSE_UNNECESSARY_COPY_ASSIGNMENT, no_bucket, ERROR, [copy assigned here (with type `const_refable::Arr&`)] +codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::read_c_str_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::modify_string2_ok_FP, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::captured_value_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] codetoanalyze/cpp/pulse/const_volatile_type.cpp, test_volatile1_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `std::unique_ptr::unique_ptr()` (modelled),is assigned to the null pointer,in call to `std::unique_ptr::unique_ptr(std::unique_ptr)` (modelled),invalid access occurs here] @@ -165,6 +185,9 @@ codetoanalyze/cpp/pulse/nullptr.cpp, createSomeDerivedClass_from_unknown_functio codetoanalyze/cpp/pulse/nullptr.cpp, test_call_nullptr_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/nullptr.cpp, call_incr_deref_with_alias_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/nullptr.cpp, test_capture_alias_bad, 11, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, call_test_after_dereference_bad, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `test_after_dereference_bad` here,parameter `x` of test_after_dereference_bad,was compared to null on line 248, column 7,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, NodeWithNext::next_data_compared_to_null_bad, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `this` of NodeWithNext::next_data_compared_to_null_bad,was compared to null on line 391, column 9,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, call_next_data_compared_to_null_with_null_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,when calling `NodeWithNext::next_data_compared_to_null_bad` here,parameter `this` of NodeWithNext::next_data_compared_to_null_bad,was compared to null on line 391, column 9,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value0_bad, 4, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value1_bad, 5, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value2_bad, 6, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] @@ -238,6 +261,7 @@ codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_assign_struct_bad, 1, PU codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_operation_struct_bad, 1, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `operator+` here,parameter `a` of operator+,invalid access occurs here] codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_function_call_bad, 1, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `mul` here,parameter `a` of mul,invalid access occurs here] codetoanalyze/cpp/pulse/reference_stability.cpp, lambda_reference_stability.cpp:792_a723a24b::operator(), 0, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `mul` here,parameter `a` of mul,invalid access occurs here] +codetoanalyze/cpp/pulse/reference_stability.cpp, folly_fastmap_try_emplace_key_only_bad, 4, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,variable `map` declared here,in call to `folly::F14FastMap::try_emplace` (modelled),was potentially invalidated by `folly::F14FastMap::try_emplace`,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `folly::F14FastMap::at` (modelled),in call to `folly::F14FastMap::at` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/reference_wrapper.cpp, reference_wrapper_heap_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `getwrapperHeap` here,in call to `WrapsB::WrapsB`,allocated by call to `new` (modelled),assigned,return from call to `WrapsB::WrapsB`,when calling `WrapsB::~WrapsB` here,parameter `this` of WrapsB::~WrapsB,when calling `WrapsB::__infer_inner_destructor_~WrapsB` here,parameter `this` of WrapsB::__infer_inner_destructor_~WrapsB,was invalidated by `delete`,use-after-lifetime part of the trace starts here,in call to `getwrapperHeap`,variable `a` declared here,in call to `WrapsB::WrapsB`,parameter `this` of WrapsB::WrapsB,allocated by call to `new` (modelled),assigned,return from call to `WrapsB::WrapsB`,in call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,parameter `a` of ReferenceWrapperHeap::ReferenceWrapperHeap,in call to `WrapsB::getb`,parameter `this` of WrapsB::getb,returned,return from call to `WrapsB::getb`,assigned,return from call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,return from call to `getwrapperHeap`,invalid access occurs here] codetoanalyze/cpp/pulse/reference_wrapper.cpp, reference_wrapper_stack_bad, 2, USE_AFTER_LIFETIME, no_bucket, ERROR, [invalidation part of the trace starts here,variable `rw` declared here,when calling `getwrapperStack` here,variable `b` declared here,is the address of a stack variable `b` whose lifetime has ended,use-after-lifetime part of the trace starts here,variable `rw` declared here,in call to `getwrapperStack`,variable `b` declared here,in call to `ReferenceWrapperStack::ReferenceWrapperStack`,parameter `bref` of ReferenceWrapperStack::ReferenceWrapperStack,assigned,return from call to `ReferenceWrapperStack::ReferenceWrapperStack`,return from call to `getwrapperStack`,invalid access occurs here] codetoanalyze/cpp/pulse/returns.cpp, returns::return_literal_stack_reference_bad, 0, STACK_VARIABLE_ADDRESS_ESCAPE, no_bucket, ERROR, [variable `C++ temporary` declared here,returned here] @@ -298,6 +322,18 @@ codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::shared_p codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::shared_ptr_move_deref_bad, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `std::shared_ptr::shared_ptr()` (modelled),is assigned to the null pointer,in call to `std::shared_ptr::operator=(std::shared_ptr) (move)` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::FP_shared_from_this_ok, 9, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::lock_primary_ptr_ok, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter primary with type `shared_ptr_semantics::PrimaryPtr,std::allocator>>`] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` accessed here,in call to `std::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_if_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_if_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::find_if()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::lower_bound_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::lower_bound_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` accessed here,in call to `std::lower_bound()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::max_element_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::max_element_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::max_element()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::next_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::next_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::next()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::advance_then_push_back_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::advance_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::advance()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_if_arrow_then_push_back_bad, 7, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_if_arrow_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::find_if()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_interproc_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_interproc_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std_algorithm::find_three`,parameter `__return_param` of std_algorithm::find_three,in call to `std::find()` (modelled),return from call to `std_algorithm::find_three`,invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_assigned_then_push_back_bad, 7, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_assigned_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator operator=` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::prev_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::prev_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::prev()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::next_prev_end_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::next()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::FP_erase_after_found_ok, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::FP_erase_after_found_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `it` accessed here,in call to `std::find()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::pre_increment_decrement_test_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::load_store_possible_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::exchange_possible_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] @@ -309,6 +345,48 @@ codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::FP_compare_exchange_strong codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::compare_exchange_strong_possible_npe1_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::FP_compare_exchange_strong_impossible_npe2_ok, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::compare_exchange_strong_possible_npe2_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_empty_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::map::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_map_find_empty_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::unordered_map::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_after_clear_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,in call to `std::map::clear()` (modelled),in call to `std::map::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_begin_empty_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::set::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_set_find_empty_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::unordered_set::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_empty_begin_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `list` of list_empty_begin_bad,in call to `std::list::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_compare_end_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_find_compare_end_bad,in call to `std::map::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_list_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_map_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_deque_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_accessor_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_iterator_loop_then_npe_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_at_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_front_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_loop_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_loop_then_npe_bad, 3, NULLPTR_DEREFERENCE_LATENT, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_back_then_use_after_delete_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `p` of call_back_then_use_after_delete_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `p` of call_back_then_use_after_delete_bad,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_front_then_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_front_then_clear_reference_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of call_front_then_clear_reference_bad,in call to `first_reference`,parameter `list` of first_reference,in call to `std::list::front()` (modelled),returned,return from call to `first_reference`,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_end_bad,in call to `std::map::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `list` of list_end_bad,in call to `std::list::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_end_bad,in call to `std::map::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),was invalidated by `std::list::erase`,use-after-lifetime part of the trace starts here,parameter `list` of list_erase_bad,in call to `std::list::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of set_erase_bad,in call to `std::set::find()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),was invalidated by `std::set::erase`,use-after-lifetime part of the trace starts here,parameter `set` of set_erase_bad,in call to `std::set::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, multiset_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of multiset_erase_bad,in call to `std::multiset::begin()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),was invalidated by `std::multiset::erase`,use-after-lifetime part of the trace starts here,parameter `set` of multiset_erase_bad,in call to `std::multiset::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_set_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of unordered_set_erase_bad,in call to `std::unordered_set::begin()` (modelled),in call to `std::__hash_const_iterator::__hash_const_iterator()` (modelled),was invalidated by `std::unordered_set::erase`,use-after-lifetime part of the trace starts here,parameter `set` of unordered_set_erase_bad,in call to `std::unordered_set::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_copy_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_copy_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_copy_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_in_loop_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_in_loop_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_in_loop_bad,in call to `std::map::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_map_erase_in_loop_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of unordered_map_erase_in_loop_bad,in call to `std::unordered_map::begin()` (modelled),in call to `std::__hash_map_iterator::__hash_map_iterator()` (modelled),was invalidated by `std::unordered_map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of unordered_map_erase_in_loop_bad,in call to `std::unordered_map::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_reference_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_reference_bad,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::operator->()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_reference_bad,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::operator->()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_clear_reference_bad,was invalidated by `std::map::clear`,use-after-lifetime part of the trace starts here,parameter `map` of map_clear_reference_bad,in call to `std::map::operator[]()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_clear_iterator_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_clear_iterator_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_clear_iterator_bad,in call to `std::list::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_clear_reference_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_clear_reference_bad,in call to `std::list::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_deref_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_deref_after_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),was invalidated by `std::list::erase`,use-after-lifetime part of the trace starts here,parameter `list` of call_deref_after_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),when calling `deref_list_iterator` here,parameter `it` of deref_list_iterator,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_clear_after_begin_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_clear_after_begin_bad,when calling `clear_list` here,parameter `list` of clear_list,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of call_clear_after_begin_bad,in call to `std::list::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_push_back_bad,was invalidated by `std::deque::push_back`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_push_back_bad,in call to `std::deque::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_push_front_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_push_front_bad,was invalidated by `std::deque::push_front`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_push_front_bad,in call to `std::deque::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_insert_bad,was invalidated by `std::deque::insert`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_insert_bad,in call to `std::deque::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_set_for_each_insert_ok, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::set::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_list_end_after_clear_ok, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `list` declared here,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,variable `list` declared here,in call to `std::list::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_map_end_after_clear_ok, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `map` declared here,was invalidated by `std::map::clear`,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::map::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp, iterate_local_set_bad, 1, PULSE_UNNECESSARY_COPY, no_bucket, ERROR, [copied here (with type `std::set const &`)] +codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp, list_front_after_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_front_after_clear_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_front_after_clear_bad,in call to `std::list::front()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::if_temporary_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::else_temporary_bad, 8, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::label_temporary_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] @@ -376,7 +454,6 @@ codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_pointer_pass_to_sin codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_pointer_pass_to_sink_bad2, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad1, 3, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad1, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter formal with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 2, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad3, 3, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::call_assign_source_by_reference`,in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,return from call to `pointers::call_assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN @@ -385,13 +462,15 @@ codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_bad0, 2, TAINT_ERRO codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad1, 1, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad2, 1, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad2, 1, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strncpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strncpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memcpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `memcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memmove_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `memmove` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strncpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `strncpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memcpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `memcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memmove_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to `memmove` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy_c_str_of_copy_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy_data_of_copy_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 2, PULSE_UNNECESSARY_COPY, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] @@ -399,22 +478,30 @@ codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor2_bad, 3, TAINT_E codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor3_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor3_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor4_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor4_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor5_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor5_bad, 5, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat1_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat1_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator+=` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat2_bad, 4, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator+=` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::append` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::assign` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::assign` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::replace` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::swap_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::swap` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN @@ -648,7 +735,27 @@ codetoanalyze/cpp/pulse/vector.cpp, shrink_to_fit_bad, 3, VECTOR_INVALIDATION, n codetoanalyze/cpp/pulse/vector.cpp, insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of insert_bad,was potentially invalidated by `std::vector::insert`,use-after-lifetime part of the trace starts here,parameter `vec` of insert_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_back_bad,was potentially invalidated by `std::vector::emplace_back`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_back_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, emplace_no_args_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_no_args_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_no_args_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, emplace_back_no_args_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_back_no_args_bad,was potentially invalidated by `std::vector::emplace_back`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_back_no_args_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of erase_bad,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of erase_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of erase_range_bad,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of erase_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, resize_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of resize_bad,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,parameter `vec` of resize_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_last_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_last_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_last_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_tail_keep_front_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_tail_keep_front_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_tail_keep_front_ok,in call to `std::vector::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_empty_range_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_empty_range_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_empty_range_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_shrinking_resize_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_shrinking_resize_ok,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_shrinking_resize_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_shrinking_resize_after_size_constructor_ok, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `vec` declared here,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,variable `vec` declared here,in call to `std::vector::data()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, assign_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of assign_range_bad,was potentially invalidated by `std::vector::assign`,use-after-lifetime part of the trace starts here,parameter `vec` of assign_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of insert_range_bad,was potentially invalidated by `std::vector::insert`,use-after-lifetime part of the trace starts here,parameter `vec` of insert_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_front_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_front_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_front_after_push_back_bad,in call to `std::vector::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_back_after_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_back_after_clear_bad,was potentially invalidated by `std::vector::clear`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_back_after_clear_bad,in call to `std::vector::back()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_data_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_data_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_data_after_push_back_bad,in call to `std::vector::data()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_back_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, resize_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, assign_count_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_size_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_range_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_read_after_emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_loop_latent, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] @@ -656,7 +763,20 @@ codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_loop_la codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_after_push_back_loop_bad, 9, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter_begin` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter_begin` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_read_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::end()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_next_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_prev_next_read_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::end()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_prev_after_emplace_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_prev_after_emplace_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_read_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, FP_iterator_before_erased_position_read_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_returned_by_erase_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_returned_by_erase_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter` accessed here,in call to `std::vector::erase()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_assigned_then_push_back_bad, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_plus_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_plus_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter` accessed here,in call to `iterator operator+` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_plus_assign_after_push_back_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_plus_assign_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `iterator operator+=` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_cend_read_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::cend()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_plus_zero_read_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `iterator operator+` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_minus_then_plus_read_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `iterator operator+` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_arrow_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_arrow_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::end()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseConstr, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter b with type `std::weak_ptr`] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseAssign, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter b with type `std::weak_ptr`] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseAssign, 2, PULSE_UNNECESSARY_COPY_ASSIGNMENT, no_bucket, ERROR, [copy assigned here (with type `std::weak_ptr&`)] diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp-11 b/infer/tests/codetoanalyze/cpp/pulse/issues.exp-11 index d1f7acc7d4..bc606cb902 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp-11 +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp-11 @@ -15,6 +15,24 @@ codetoanalyze/cpp/pulse/array_init.cpp, array_init::FP_constructor_filler_leak_o codetoanalyze/cpp/pulse/basic_string.cpp, use_range_of_invalidated_temporary_string_bad, 2, USE_AFTER_DELETE_LATENT, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `setLanguage` here,variable `C++ temporary` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `Range::Range`,parameter `str` of Range::Range,return from call to `Range::Range`,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,struct field address `b_` created,in call to `setLanguage`,parameter `__return_param` of setLanguage,variable `C++ temporary` declared here,struct field address `b_` created,variable `C++ temporary` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `Range::Range`,parameter `this` of Range::Range,parameter `str` of Range::Range,in call to `std::basic_string::data()` (modelled),in call to `std::basic_string::data()` (modelled),assigned,return from call to `Range::Range`,in call to `Range::Range`,parameter `__param_0` of Range::Range,parameter `this` of Range::Range,assigned,return from call to `Range::Range`,return from call to `setLanguage`,in call to `Range::Range`,parameter `__param_0` of Range::Range,assigned,return from call to `Range::Range`,when calling `Range::operator[]` here,parameter `this` of Range::operator[],invalid access occurs here] codetoanalyze/cpp/pulse/basic_string.cpp, copy_string_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/basic_string.cpp, copy_string_ok, 2, PULSE_UNNECESSARY_COPY, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_of_temporary_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_after_scope_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, use_c_str_of_local_bad, 0, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `c_str_of_local` here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,in call to `c_str_of_local`,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),returned,return from call to `c_str_of_local`,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, data_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of data_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of data_then_append_bad,in call to `std::basic_string::data()` (modelled),in call to `std::basic_string::data()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_push_back_bad,was potentially invalidated by `std::basic_string::push_back`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_push_back_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_plus_assign_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_plus_assign_bad,was potentially invalidated by `std::basic_string::operator+=`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_plus_assign_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_assign_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_assign_bad,was potentially invalidated by `std::basic_string::operator=`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_assign_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_clear_bad,was potentially invalidated by `std::basic_string::clear`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_clear_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_insert_bad,was potentially invalidated by `std::basic_string::insert`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_insert_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_reserve_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_reserve_bad,was potentially invalidated by `std::basic_string::reserve`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_reserve_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_append_in_callee_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_append_in_callee_bad,when calling `append_to` here,parameter `s` of append_to,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_append_in_callee_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_erase_bad,was potentially invalidated by `std::basic_string::erase`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_erase_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_then_pop_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_then_pop_back_bad,was potentially invalidated by `std::basic_string::pop_back`,use-after-lifetime part of the trace starts here,parameter `s` of c_str_then_pop_back_bad,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_after_reserve_then_append_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_after_reserve_then_append_bad,was potentially invalidated by `std::basic_string::operator+=`,use-after-lifetime part of the trace starts here,in call to function `std::basic_string,std::allocator>::reserve` with no summary,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, c_str_of_append_result_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of c_str_of_append_result_then_push_back_bad,was potentially invalidated by `std::basic_string::push_back`,use-after-lifetime part of the trace starts here,in call to function `std::basic_string,std::allocator>::append` with no summary,in call to `std::basic_string::c_str()` (modelled),in call to `std::basic_string::c_str()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, begin_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of begin_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,parameter `s` of begin_then_append_bad,in call to `std::basic_string::begin()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, find_then_append_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `s` of find_then_append_bad,was potentially invalidated by `std::basic_string::append`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/basic_string.cpp, assigned_begin_after_scope_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),in call to `std::basic_string::~basic_string()` (modelled),was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `s` declared here,in call to `std::basic_string::basic_string()` (modelled),in call to `std::basic_string::begin()` (modelled),in call to `iterator operator=` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_branch_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_branch_bad, 6, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_branch_bad,invalid access occurs here] codetoanalyze/cpp/pulse/basics.cpp, multiple_invalidations_loop_bad, 5, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `ptr` of multiple_invalidations_loop_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `ptr` of multiple_invalidations_loop_bad,invalid access occurs here] @@ -81,6 +99,7 @@ codetoanalyze/cpp/pulse/conditionals.cpp, binary_and_bad, 3, USE_AFTER_FREE, no_ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::read_first_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter a with type `const_refable::Arr`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::interprocedural_read_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::sum_in_loop_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] +codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::sum_set_in_loop_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter set with type `std::set,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::std_pair_vector_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter p with type `std::pair>>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::std_pair_string_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter p with type `std::pair,std::allocator>,std::basic_string,std::allocator>>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::folly_optional_vector_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec_opt with type `folly::Optional>>`] @@ -88,6 +107,7 @@ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::folly_optional_string_ codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::havoc_reachable_by_unknown_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `const_refable::StructWithInt`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::AssignField::assign_field_bad, 0, PULSE_UNNECESSARY_COPY_ASSIGNMENT, no_bucket, ERROR, [copy assigned here (with type `const_refable::Arr&`)] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::AssignField::assign_global_bad, 0, PULSE_UNNECESSARY_COPY_ASSIGNMENT, no_bucket, ERROR, [copy assigned here (with type `const_refable::Arr&`)] +codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::read_c_str_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::modify_string2_ok_FP, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter s with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/const_refable.cpp, const_refable::captured_value_bad, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter vec with type `std::vector>`] codetoanalyze/cpp/pulse/const_volatile_type.cpp, test_volatile1_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `std::unique_ptr::unique_ptr()` (modelled),is assigned to the null pointer,in call to `std::unique_ptr::unique_ptr(std::unique_ptr)` (modelled),invalid access occurs here] @@ -177,6 +197,9 @@ codetoanalyze/cpp/pulse/nullptr.cpp, createSomeDerivedClass_from_unknown_functio codetoanalyze/cpp/pulse/nullptr.cpp, test_call_nullptr_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/nullptr.cpp, call_incr_deref_with_alias_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/nullptr.cpp, test_capture_alias_good, 11, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, call_test_after_dereference_bad, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `test_after_dereference_bad` here,parameter `x` of test_after_dereference_bad,was compared to null on line 248, column 7,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, NodeWithNext::next_data_compared_to_null_bad, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `this` of NodeWithNext::next_data_compared_to_null_bad,was compared to null on line 391, column 9,invalid access occurs here] +codetoanalyze/cpp/pulse/nullptr.cpp, call_next_data_compared_to_null_with_null_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,when calling `NodeWithNext::next_data_compared_to_null_bad` here,parameter `this` of NodeWithNext::next_data_compared_to_null_bad,was compared to null on line 391, column 9,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value0_bad, 4, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value1_bad, 5, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] codetoanalyze/cpp/pulse/optional.cpp, not_none_check_value2_bad, 6, OPTIONAL_EMPTY_ACCESS, no_bucket, ERROR, [in call to `folly::Optional::Optional(=None)` (modelled),is assigned an empty value,invalid access occurs here] @@ -250,6 +273,7 @@ codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_assign_struct_bad, 1, PU codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_operation_struct_bad, 1, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `operator+` here,parameter `a` of operator+,invalid access occurs here] codetoanalyze/cpp/pulse/reference_stability.cpp, unsafe_function_call_bad, 1, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `mul` here,parameter `a` of mul,invalid access occurs here] codetoanalyze/cpp/pulse/reference_stability.cpp, lambda_reference_stability.cpp:792_a723a24b::operator(), 0, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),was potentially invalidated by `folly::F14FastMap::operator[]`,use-after-lifetime part of the trace starts here,in call to `folly::F14FastMap::operator[]` (modelled),in call to `folly::F14FastMap::operator[]` (modelled),when calling `mul` here,parameter `a` of mul,invalid access occurs here] +codetoanalyze/cpp/pulse/reference_stability.cpp, folly_fastmap_try_emplace_key_only_bad, 4, PULSE_REFERENCE_STABILITY, no_bucket, ERROR, [invalidation part of the trace starts here,variable `map` declared here,in call to `folly::F14FastMap::try_emplace` (modelled),was potentially invalidated by `folly::F14FastMap::try_emplace`,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `folly::F14FastMap::at` (modelled),in call to `folly::F14FastMap::at` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/reference_wrapper.cpp, reference_wrapper_heap_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,when calling `getwrapperHeap` here,in call to `WrapsB::WrapsB`,allocated by call to `new` (modelled),assigned,return from call to `WrapsB::WrapsB`,when calling `WrapsB::~WrapsB` here,parameter `this` of WrapsB::~WrapsB,when calling `WrapsB::__infer_inner_destructor_~WrapsB` here,parameter `this` of WrapsB::__infer_inner_destructor_~WrapsB,was invalidated by `delete`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `getwrapperHeap`,parameter `__return_param` of getwrapperHeap,variable `a` declared here,in call to `WrapsB::WrapsB`,parameter `this` of WrapsB::WrapsB,allocated by call to `new` (modelled),assigned,return from call to `WrapsB::WrapsB`,variable `C++ temporary` declared here,in call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,parameter `a` of ReferenceWrapperHeap::ReferenceWrapperHeap,parameter `this` of ReferenceWrapperHeap::ReferenceWrapperHeap,in call to `WrapsB::getb`,parameter `this` of WrapsB::getb,returned,return from call to `WrapsB::getb`,assigned,return from call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,in call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,parameter `__param_0` of ReferenceWrapperHeap::ReferenceWrapperHeap,parameter `this` of ReferenceWrapperHeap::ReferenceWrapperHeap,assigned,return from call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,return from call to `getwrapperHeap`,in call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,parameter `__param_0` of ReferenceWrapperHeap::ReferenceWrapperHeap,assigned,return from call to `ReferenceWrapperHeap::ReferenceWrapperHeap`,invalid access occurs here] codetoanalyze/cpp/pulse/reference_wrapper.cpp, reference_wrapper_stack_bad, 2, USE_AFTER_LIFETIME, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,when calling `getwrapperStack` here,variable `b` declared here,is the address of a stack variable `b` whose lifetime has ended,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `getwrapperStack`,parameter `__return_param` of getwrapperStack,variable `b` declared here,variable `C++ temporary` declared here,in call to `ReferenceWrapperStack::ReferenceWrapperStack`,parameter `this` of ReferenceWrapperStack::ReferenceWrapperStack,parameter `bref` of ReferenceWrapperStack::ReferenceWrapperStack,assigned,return from call to `ReferenceWrapperStack::ReferenceWrapperStack`,in call to `ReferenceWrapperStack::ReferenceWrapperStack`,parameter `__param_0` of ReferenceWrapperStack::ReferenceWrapperStack,parameter `this` of ReferenceWrapperStack::ReferenceWrapperStack,assigned,return from call to `ReferenceWrapperStack::ReferenceWrapperStack`,return from call to `getwrapperStack`,in call to `ReferenceWrapperStack::ReferenceWrapperStack`,parameter `__param_0` of ReferenceWrapperStack::ReferenceWrapperStack,assigned,return from call to `ReferenceWrapperStack::ReferenceWrapperStack`,invalid access occurs here] codetoanalyze/cpp/pulse/returns.cpp, returns::return_literal_stack_reference_bad, 0, STACK_VARIABLE_ADDRESS_ESCAPE, no_bucket, ERROR, [variable `C++ temporary` declared here,returned here] @@ -310,6 +334,18 @@ codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::shared_p codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::shared_ptr_move_deref_bad, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `std::shared_ptr::shared_ptr()` (modelled),is assigned to the null pointer,in call to `std::shared_ptr::operator=(std::shared_ptr) (move)` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::FP_shared_from_this_ok, 9, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/shared_ptr_semantics.cpp, shared_ptr_semantics::lock_primary_ptr_ok, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter primary with type `shared_ptr_semantics::PrimaryPtr,std::allocator>>`] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_if_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_if_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find_if()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::lower_bound_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::lower_bound_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::lower_bound()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::max_element_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::max_element_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::max_element()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::next_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::next_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::next()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::advance_then_push_back_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::advance_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `it` declared here,in call to `std::advance()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_if_arrow_then_push_back_bad, 7, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_if_arrow_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find_if()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_interproc_then_push_back_bad, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_interproc_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,parameter `vec` of std_algorithm::find_interproc_then_push_back_bad,in call to `std_algorithm::find_three`,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator constructor` (modelled),return from call to `std_algorithm::find_three`,in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::find_assigned_then_push_back_bad, 7, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::find_assigned_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator operator=` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::prev_then_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::prev_then_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::prev()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::next_prev_end_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::next()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_algorithm.cpp, std_algorithm::FP_erase_after_found_ok, 6, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of std_algorithm::FP_erase_after_found_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::find()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::pre_increment_decrement_test_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::load_store_possible_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::exchange_possible_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] @@ -321,6 +357,48 @@ codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::FP_compare_exchange_strong codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::compare_exchange_strong_possible_npe1_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::FP_compare_exchange_strong_impossible_npe2_ok, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/std_atomics.cpp, atomic_test::compare_exchange_strong_possible_npe2_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_empty_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_map_find_empty_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::unordered_map::find()` (modelled),in call to `std::__hash_map_iterator::__hash_map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_after_clear_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,in call to `std::map::clear()` (modelled),in call to `std::map::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_begin_empty_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::set::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_set_find_empty_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::unordered_set::find()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_empty_begin_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `list` of list_empty_begin_bad,in call to `std::list::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_find_compare_end_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_find_compare_end_bad,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_list_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_map_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_member_deque_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, range_for_accessor_then_npe_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_iterator_loop_then_npe_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_at_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_front_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_loop_then_npe_bad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_loop_then_npe_bad, 3, NULLPTR_DEREFERENCE_LATENT, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_back_then_use_after_delete_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `p` of call_back_then_use_after_delete_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `p` of call_back_then_use_after_delete_bad,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_front_then_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_front_then_clear_reference_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of call_front_then_clear_reference_bad,in call to `first_reference`,parameter `list` of first_reference,in call to `std::list::front()` (modelled),returned,return from call to `first_reference`,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_end_bad,in call to `std::map::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `list` of list_end_bad,in call to `std::list::end()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_end_bad, 0, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_end_bad,in call to `std::map::end()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),was invalidated by `std::list::erase`,use-after-lifetime part of the trace starts here,parameter `list` of list_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, set_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of set_erase_bad,in call to `std::set::find()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),was invalidated by `std::set::erase`,use-after-lifetime part of the trace starts here,parameter `set` of set_erase_bad,in call to `std::set::find()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, multiset_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of multiset_erase_bad,in call to `std::multiset::begin()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),was invalidated by `std::multiset::erase`,use-after-lifetime part of the trace starts here,parameter `set` of multiset_erase_bad,in call to `std::multiset::begin()` (modelled),in call to `std::__tree_const_iterator::__tree_const_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_set_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `set` of unordered_set_erase_bad,in call to `std::unordered_set::begin()` (modelled),in call to `std::__hash_const_iterator::__hash_const_iterator()` (modelled),in call to `std::__hash_const_iterator::__hash_const_iterator()` (modelled),was invalidated by `std::unordered_set::erase`,use-after-lifetime part of the trace starts here,parameter `set` of unordered_set_erase_bad,in call to `std::unordered_set::begin()` (modelled),in call to `std::__hash_const_iterator::__hash_const_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_copy_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_copy_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_copy_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_in_loop_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_in_loop_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_in_loop_bad,in call to `std::map::begin()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, unordered_map_erase_in_loop_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of unordered_map_erase_in_loop_bad,in call to `std::unordered_map::begin()` (modelled),in call to `std::__hash_map_iterator::__hash_map_iterator()` (modelled),in call to `std::__hash_map_iterator::__hash_map_iterator()` (modelled),was invalidated by `std::unordered_map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of unordered_map_erase_in_loop_bad,in call to `std::unordered_map::begin()` (modelled),in call to `std::__hash_map_iterator::__hash_map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_erase_reference_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_erase_reference_bad,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),in call to `std::__map_iterator::operator->()` (modelled),was invalidated by `std::map::erase`,use-after-lifetime part of the trace starts here,parameter `map` of map_erase_reference_bad,in call to `std::map::find()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),in call to `std::__map_iterator::operator->()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, map_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `map` of map_clear_reference_bad,was invalidated by `std::map::clear`,use-after-lifetime part of the trace starts here,parameter `map` of map_clear_reference_bad,in call to `std::map::operator[]()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_clear_iterator_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_clear_iterator_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_clear_iterator_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, list_clear_reference_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_clear_reference_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_clear_reference_bad,in call to `std::list::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_deref_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_deref_after_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),in call to `std::__list_const_iterator::__list_const_iterator()` (modelled),was invalidated by `std::list::erase`,use-after-lifetime part of the trace starts here,parameter `list` of call_deref_after_erase_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),when calling `deref_list_iterator` here,parameter `it` of deref_list_iterator,invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, call_clear_after_begin_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of call_clear_after_begin_bad,when calling `clear_list` here,parameter `list` of clear_list,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of call_clear_after_begin_bad,in call to `std::list::begin()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_push_back_bad,was invalidated by `std::deque::push_back`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_push_back_bad,in call to `std::deque::begin()` (modelled),in call to `std::__deque_iterator::__deque_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_push_front_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_push_front_bad,was invalidated by `std::deque::push_front`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_push_front_bad,in call to `std::deque::end()` (modelled),in call to `std::__deque_iterator::__deque_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, deque_insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `deque` of deque_insert_bad,was invalidated by `std::deque::insert`,use-after-lifetime part of the trace starts here,parameter `deque` of deque_insert_bad,in call to `std::deque::begin()` (modelled),in call to `std::__deque_iterator::__deque_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_set_for_each_insert_ok, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `set` declared here,in call to `std::set::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_list_end_after_clear_ok, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `list` declared here,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,variable `list` declared here,in call to `std::list::end()` (modelled),in call to `std::__list_iterator::__list_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers.cpp, FP_map_end_after_clear_ok, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `map` declared here,was invalidated by `std::map::clear`,use-after-lifetime part of the trace starts here,variable `map` declared here,in call to `std::map::end()` (modelled),in call to `std::__map_iterator::__map_iterator()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp, iterate_local_set_bad, 1, PULSE_UNNECESSARY_COPY, no_bucket, ERROR, [copied here (with type `std::set const &`)] +codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp, list_front_after_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `list` of list_front_after_clear_bad,was invalidated by `std::list::clear`,use-after-lifetime part of the trace starts here,parameter `list` of list_front_after_clear_bad,in call to `std::list::front()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::if_temporary_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::else_temporary_bad, 8, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/sub_statements.cpp, sub_statements::label_temporary_bad, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] @@ -388,7 +466,6 @@ codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_pointer_pass_to_sin codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_pointer_pass_to_sink_bad2, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad1, 3, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad1, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter formal with type `std::basic_string,std::allocator>`] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 2, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad2, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::assign_source_by_reference_bad3, 3, TAINT_ERROR, no_bucket, ERROR, [in call to `pointers::call_assign_source_by_reference`,in call to `pointers::assign_source_by_reference`,source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::operator=` with no summary,return from call to `pointers::assign_source_by_reference`,return from call to `pointers::call_assign_source_by_reference`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN @@ -397,13 +474,15 @@ codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_bad0, 2, TAINT_ERRO codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad1, 1, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad2, 1, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/pointers.cpp, pointers::funptr_helper_bad2, 1, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strncpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `strncpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memcpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `memcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memmove_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::c_str` with no summary,in call to `memmove` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::sprintf2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `sprintf` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy1_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `strcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strncpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `strncpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memcpy_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `memcpy` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::memmove_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to `memmove` (modelled),in call to function `std::basic_string,std::allocator>::basic_string<0>` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy_c_str_of_copy_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::strcpy_data_of_copy_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor1_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] @@ -411,22 +490,30 @@ codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor2_bad, 3, TAINT_E codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor3_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor3_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor4_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor4_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor5_bad, 5, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::constructor5_bad, 5, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat1_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat1_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat2_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::operator+=` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat2_bad, 4, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] -codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::operator+=` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::concat3_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::append` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::append2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::assign` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::assign2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::assign` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::insert2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace1_bad, 2, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::replace` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN +codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace1_bad, 2, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace2_bad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN codetoanalyze/cpp/pulse/taint/strings.cpp, strings::replace2_bad, 3, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::basic_string,std::allocator>&`)] codetoanalyze/cpp/pulse/taint/strings.cpp, strings::swap_bad, 4, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value returned from `__infer_taint_source` with kind `SimpleSource`,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,in call to function `std::basic_string,std::allocator>::swap` with no summary,in call to function `std::basic_string,std::allocator>::basic_string` with no summary,flows to this sink: value passed as argument `#0` to `__infer_taint_sink` with kind `SimpleSink`], source: __infer_taint_source, sink: __infer_taint_sink, tainted expression: UNKNOWN @@ -657,7 +744,27 @@ codetoanalyze/cpp/pulse/vector.cpp, shrink_to_fit_bad, 3, VECTOR_INVALIDATION, n codetoanalyze/cpp/pulse/vector.cpp, insert_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of insert_bad,was potentially invalidated by `std::vector::insert`,use-after-lifetime part of the trace starts here,parameter `vec` of insert_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_back_bad,was potentially invalidated by `std::vector::emplace_back`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_back_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, emplace_no_args_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_no_args_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_no_args_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, emplace_back_no_args_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of emplace_back_no_args_bad,was potentially invalidated by `std::vector::emplace_back`,use-after-lifetime part of the trace starts here,parameter `vec` of emplace_back_no_args_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of erase_bad,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of erase_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of erase_range_bad,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of erase_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, resize_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of resize_bad,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,parameter `vec` of resize_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_last_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_last_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_last_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_tail_keep_front_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_tail_keep_front_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_tail_keep_front_ok,in call to `std::vector::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_erase_empty_range_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_erase_empty_range_ok,was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_erase_empty_range_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_shrinking_resize_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of FP_shrinking_resize_ok,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,parameter `vec` of FP_shrinking_resize_ok,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, FP_shrinking_resize_after_size_constructor_ok, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `vec` declared here,was potentially invalidated by `std::vector::resize`,use-after-lifetime part of the trace starts here,variable `vec` declared here,in call to `std::vector::data()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, assign_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of assign_range_bad,was potentially invalidated by `std::vector::assign`,use-after-lifetime part of the trace starts here,parameter `vec` of assign_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_range_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of insert_range_bad,was potentially invalidated by `std::vector::insert`,use-after-lifetime part of the trace starts here,parameter `vec` of insert_range_bad,in call to `std::vector::at()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_front_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_front_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_front_after_push_back_bad,in call to `std::vector::front()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_back_after_clear_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_back_after_clear_bad,was potentially invalidated by `std::vector::clear`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_back_after_clear_bad,in call to `std::vector::back()` (modelled),assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, deref_data_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of deref_data_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,parameter `vec` of deref_data_after_push_back_bad,in call to `std::vector::data()` (modelled),assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector.cpp, emplace_back_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, resize_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, assign_count_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, erase_size_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/cpp/pulse/vector.cpp, insert_range_size_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_read_after_emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_loop_latent, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] @@ -665,7 +772,20 @@ codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_emplace_loop_la codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_after_push_back_loop_bad, 9, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_read_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::end()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_next_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::end()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_prev_next_read_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::end()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_prev_after_emplace_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_prev_after_emplace_bad,was potentially invalidated by `std::vector::emplace`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_read_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_next_after_erase_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, FP_iterator_before_erased_position_read_ok, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::erase`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_returned_by_erase_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_returned_by_erase_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `std::vector::erase()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_assigned_then_push_back_bad, 5, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_plus_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_plus_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `iterator operator+` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_plus_assign_after_push_back_bad, 4, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `vec` of iterator_plus_assign_after_push_back_bad,was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `iter` declared here,in call to `iterator operator+=` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_cend_read_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::cend()` (modelled),in call to `iterator constructor` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_plus_zero_read_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` accessed here,in call to `iterator operator+` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_minus_then_plus_read_bad, 2, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `iterator operator+` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_arrow_after_push_back_bad, 3, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),was potentially invalidated by `std::vector::push_back`,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::begin()` (modelled),invalid access occurs here] +codetoanalyze/cpp/pulse/vector_iterator.cpp, iterator_end_arrow_bad, 1, VECTOR_INVALIDATION, no_bucket, ERROR, [invalidation part of the trace starts here,is pointed to by the `end()` iterator,use-after-lifetime part of the trace starts here,variable `C++ temporary` declared here,in call to `std::vector::end()` (modelled),invalid access occurs here] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseConstr, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter b with type `std::weak_ptr`] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseConstr, 1, PULSE_UNNECESSARY_COPY_INTERMEDIATE, no_bucket, ERROR, [copied here (with type `std::weak_ptr&`)] codetoanalyze/cpp/pulse/weak_ptr.cpp, weak_ptr_constructors::fromWeakBaseAssign, 0, PULSE_CONST_REFABLE, no_bucket, ERROR, [Parameter b with type `std::weak_ptr`] diff --git a/infer/tests/codetoanalyze/cpp/pulse/nullptr.cpp b/infer/tests/codetoanalyze/cpp/pulse/nullptr.cpp index f3fc4b58a7..70e1e372bd 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/nullptr.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/nullptr.cpp @@ -380,3 +380,24 @@ void test_capture_alias_good(void) { } x = *ptr; } + +void call_test_after_dereference_bad() { test_after_dereference_bad(nullptr); } + +struct NodeWithNext { + NodeWithNext* next; + int data; + + int next_data_compared_to_null_bad() { + if (next == nullptr) { + log_null(); + } + return next->data; + } + + static void log_null(); +}; + +int call_next_data_compared_to_null_with_null_bad() { + NodeWithNext n{nullptr, 0}; + return n.next_data_compared_to_null_bad(); +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/reference_stability.cpp b/infer/tests/codetoanalyze/cpp/pulse/reference_stability.cpp index b12ec83b46..987752afd6 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/reference_stability.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/reference_stability.cpp @@ -791,3 +791,10 @@ void unsafe_function_call_bad(folly::F14FastMap& map) { void unsafe_function_call_lambda_bad(folly::F14FastMap&& map) { [&]() { const auto result = mul(map[13], map[71]); }; } + +void folly_fastmap_try_emplace_key_only_bad() { + folly::F14FastMap map = {{1, 1}, {2, 4}, {3, 9}}; + const auto& valueRef = map.at(1); + map.try_emplace(4); + const auto valueCopy = valueRef; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/std_algorithm.cpp b/infer/tests/codetoanalyze/cpp/pulse/std_algorithm.cpp new file mode 100644 index 0000000000..e79844d896 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse/std_algorithm.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include +#include +#include +#include + +namespace std_algorithm { + +int find_then_push_back_bad(std::vector& vec) { + auto it = std::find(vec.begin(), vec.end(), 3); + if (it == vec.end()) { + return 0; + } + vec.push_back(1); + return *it; +} + +int find_if_then_push_back_bad(std::vector& vec) { + auto it = std::find_if(vec.begin(), vec.end(), [](int x) { return x > 3; }); + if (it == vec.end()) { + return 0; + } + vec.push_back(1); + return *it; +} + +int lower_bound_then_push_back_bad(std::vector& vec) { + auto it = std::lower_bound(vec.begin(), vec.end(), 3); + vec.push_back(1); + return *it; +} + +int max_element_then_push_back_bad(std::vector& vec) { + auto it = std::max_element(vec.begin(), vec.end()); + vec.push_back(1); + return *it; +} + +int next_then_push_back_bad(std::vector& vec) { + auto it = std::next(vec.begin()); + vec.push_back(1); + return *it; +} + +int advance_then_push_back_bad(std::vector& vec) { + auto it = vec.begin(); + std::advance(it, 1); + vec.push_back(1); + return *it; +} + +struct Elem { + int x; +}; + +int find_if_arrow_then_push_back_bad(std::vector& vec) { + auto it = std::find_if( + vec.begin(), vec.end(), [](const Elem& e) { return e.x > 3; }); + if (it == vec.end()) { + return 0; + } + vec.push_back(Elem{1}); + return it->x; +} + +std::vector::iterator find_three(std::vector& vec) { + return std::find(vec.begin(), vec.end(), 3); +} + +int find_interproc_then_push_back_bad(std::vector& vec) { + auto it = find_three(vec); + if (it == vec.end()) { + return 0; + } + vec.push_back(1); + return *it; +} + +int find_assigned_then_push_back_bad(std::vector& vec) { + auto it = vec.end(); + it = std::find(vec.begin(), vec.end(), 3); + if (it == vec.end()) { + return 0; + } + vec.push_back(1); + return *it; +} + +int find_checked_ok(std::vector& vec) { + auto it = std::find(vec.begin(), vec.end(), 3); + if (it != vec.end()) { + return *it; + } + return 0; +} + +int find_checked_saved_end_ok(std::vector& vec) { + auto end = vec.end(); + auto it = std::find(vec.begin(), end, 3); + if (it != end) { + return *it; + } + return 0; +} + +int find_checked_cend_ok(const std::vector& vec) { + auto it = std::find(vec.cbegin(), vec.cend(), 3); + if (it == vec.cend()) { + return 0; + } + return *it; +} + +int find_present_element_ok(std::vector& vec) { + vec.push_back(3); + return *std::find(vec.begin(), vec.end(), 3); +} + +// the models have no case for "not found" +int FN_find_on_empty_bad() { + std::vector vec; + return *std::find(vec.begin(), vec.end(), 3); +} + +int find_after_reserve_ok(std::vector& vec) { + vec.reserve(vec.size() + 1); + auto it = std::find(vec.begin(), vec.end(), 3); + if (it == vec.end()) { + return 0; + } + vec.push_back(1); + return *it; +} + +int find_again_after_push_back_ok(std::vector& vec) { + auto it = std::find(vec.begin(), vec.end(), 3); + if (it == vec.end()) { + vec.push_back(3); + it = std::find(vec.begin(), vec.end(), 3); + } + return *it; +} + +int prev_end_ok(std::vector& vec) { + if (vec.empty()) { + return 0; + } + return *std::prev(vec.end()); +} + +int prev_then_push_back_bad(std::vector& vec) { + auto it = std::prev(vec.end()); + vec.push_back(1); + return *it; +} + +int next_prev_end_bad(std::vector& vec) { + return *std::next(std::prev(vec.end())); +} + +int next_prev_round_trip_ok(std::vector& vec) { + auto it = vec.begin(); + if (std::prev(std::next(it, 2), 2) != it) { + int* q = nullptr; + return *q; + } + return 0; +} + +int next_same_as_plus_ok(std::vector::iterator it) { + if (std::next(it, 2) != it + 2) { + int* q = nullptr; + return *q; + } + return 0; +} + +int advance_base_ok(std::vector::iterator it) { + std::vector::iterator it_copy; + it_copy = it; + std::advance(it_copy, 2); + if (it_copy.base() != it.base() + 2) { + int* q = nullptr; + return *q; + } + return 0; +} + +// erase invalidates the elements before the erased range too +int FP_erase_after_found_ok(std::vector& vec) { + auto it = std::find(vec.begin(), vec.end(), 3); + if (it == vec.end()) { + return 0; + } + vec.erase(std::next(it), vec.end()); + return *it; +} + +void erase_remove_if_ok(std::vector& vec) { + vec.erase(std::remove_if(vec.begin(), vec.end(), [](int x) { return x < 0; }), + vec.end()); +} + +std::vector rotate_copy_ok(const std::vector& vec) { + auto copy = vec; + std::rotate(copy.begin(), copy.begin() + 1, copy.end()); + return copy; +} + +int partition_elements_ok(std::vector& vec) { + int x = 0; + if (vec.size() != 2) { + return 0; + } + vec[0] = nullptr; + vec[1] = &x; + std::partition(vec.begin(), vec.end(), [](int* p) { return p != nullptr; }); + return *vec[0]; +} + +char find_in_string_ok(const std::string& s) { + auto it = std::find(s.begin(), s.end(), 'a'); + if (it != s.end()) { + return *it; + } + return 'b'; +} + +} // namespace std_algorithm diff --git a/infer/tests/codetoanalyze/cpp/pulse/std_containers.cpp b/infer/tests/codetoanalyze/cpp/pulse/std_containers.cpp new file mode 100644 index 0000000000..70acaaacd5 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse/std_containers.cpp @@ -0,0 +1,558 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +int map_find_empty_bad() { + std::map map; + auto it = map.find(1); + return it->second; +} + +int unordered_map_find_empty_bad() { + std::unordered_map map; + auto it = map.find(1); + return it->second; +} + +int map_find_after_clear_bad(std::map& map) { + map.clear(); + return map.find(1)->second; +} + +int set_begin_empty_bad() { + std::set set; + return *set.begin(); +} + +int unordered_set_find_empty_bad() { + std::unordered_set set; + return *set.find(1); +} + +int list_empty_begin_bad(std::list& list) { + if (list.empty()) { + return *list.begin(); + } + return 0; +} + +int map_find_compare_end_bad(std::map& map) { + auto it = map.find(1); + if (it == map.end()) { + return it->second; + } + return 0; +} + +struct Containers { + std::list list; + std::map map; + std::deque deque; + const std::list& get_list() const { return list; } +}; + +int range_for_member_list_then_npe_bad(Containers& containers) { + for (int x : containers.list) { + (void)x; + } + int* p = nullptr; + return *p; +} + +int range_for_member_map_then_npe_bad(Containers& containers) { + for (const auto& entry : containers.map) { + (void)entry; + } + int* p = nullptr; + return *p; +} + +int range_for_member_deque_then_npe_bad(Containers& containers) { + for (int x : containers.deque) { + (void)x; + } + int* p = nullptr; + return *p; +} + +int range_for_accessor_then_npe_bad(const Containers& containers) { + for (int x : containers.get_list()) { + (void)x; + } + int* p = nullptr; + return *p; +} + +int set_iterator_loop_then_npe_bad(std::set& set) { + for (auto it = set.begin(); it != set.end(); ++it) { + if (*it == 0) { + break; + } + } + int* p = nullptr; + return *p; +} + +int lookup(const std::map& map, int key) { return map.at(key); } + +int call_at_then_npe_bad(std::map& map) { + int value = lookup(map, 1); + int* p = nullptr; + return *p + value; +} + +int first_value(std::list& list) { return list.front(); } + +int call_front_then_npe_bad(std::list& list) { + int value = first_value(list); + int* p = nullptr; + return *p + value; +} + +int list_sum(const std::list& list) { + int sum = 0; + for (int x : list) { + sum += x; + } + return sum; +} + +int call_loop_then_npe_bad(std::list& list) { + int value = list_sum(list); + int* p = nullptr; + return *p + value; +} + +int last_value(std::deque& deque) { return deque.back(); } + +int call_back_then_use_after_delete_bad(std::deque& deque, int* p) { + delete p; + int value = last_value(deque); + return *p + value; +} + +int& first_reference(std::list& list) { return list.front(); } + +int call_front_then_clear_reference_bad(std::list& list) { + int& front = first_reference(list); + list.clear(); + return front; +} + +int at_then_empty_ok(std::map& map) { + int value = map.at(1); + if (map.empty()) { + int* p = nullptr; + return *p; + } + return value; +} + +int call_at_then_empty_ok(std::map& map) { + int value = lookup(map, 1); + if (map.empty()) { + int* p = nullptr; + return *p; + } + return value; +} + +int map_end_bad(std::map& map) { return map.end()->second; } + +int list_end_bad(std::list& list) { return *list.end(); } + +void map_erase_end_bad(std::map& map) { map.erase(map.end()); } + +int list_erase_bad(std::list& list) { + auto it = list.begin(); + list.erase(it); + return *it; +} + +int set_erase_bad(std::set& set) { + auto it = set.find(1); + set.erase(it); + return *it; +} + +int multiset_erase_bad(std::multiset& set) { + auto it = set.begin(); + set.erase(it); + return *it; +} + +int unordered_set_erase_bad(std::unordered_set& set) { + auto it = set.begin(); + set.erase(it); + return *it; +} + +int map_erase_copy_bad(std::map& map) { + auto it = map.begin(); + auto it2 = it; + map.erase(it); + return it2->second; +} + +void map_erase_in_loop_bad(std::map& map) { + for (auto it = map.begin(); it != map.end(); ++it) { + if (it->second == 0) { + map.erase(it); + } + } +} + +void unordered_map_erase_in_loop_bad(std::unordered_map& map) { + for (auto it = map.begin(); it != map.end(); ++it) { + if (it->second == 0) { + map.erase(it); + } + } +} + +int map_erase_reference_bad(std::map& map) { + auto it = map.find(1); + const int& value = it->second; + map.erase(it); + return value; +} + +int map_clear_reference_bad(std::map& map) { + const int& value = map[1]; + map.clear(); + return value; +} + +int list_clear_iterator_bad(std::list& list) { + auto it = list.begin(); + list.clear(); + return *it; +} + +int list_clear_reference_bad(std::list& list) { + const int& front = list.front(); + list.clear(); + return front; +} + +int deref_list_iterator(std::list::iterator it) { return *it; } + +int call_deref_after_erase_bad(std::list& list) { + auto it = list.begin(); + list.erase(it); + return deref_list_iterator(it); +} + +void clear_list(std::list& list) { list.clear(); } + +int call_clear_after_begin_bad(std::list& list) { + auto it = list.begin(); + clear_list(list); + return *it; +} + +int deque_push_back_bad(std::deque& deque) { + auto it = deque.begin(); + deque.push_back(1); + return *it; +} + +int deque_push_front_bad(std::deque& deque) { + auto it = deque.end(); + deque.push_front(1); + --it; + return *it; +} + +int deque_insert_bad(std::deque& deque) { + auto it = deque.begin(); + deque.insert(deque.end(), 1); + return *it; +} + +int map_find_checked_ok(std::map& map) { + auto it = map.find(1); + if (it != map.end()) { + return it->second; + } + return 0; +} + +// whether the key is present is unknown so the lookup is not reported +int map_find_unchecked_ok(std::map& map) { + return map.find(1)->second; +} + +int map_find_after_insert_ok() { + std::map map; + map[1] = 2; + return map.find(1)->second; +} + +int map_insert_find_ok() { + std::map map; + auto result = map.insert({1, 2}); + if (result.second) { + return result.first->second; + } + return map.find(1)->second; +} + +int unordered_map_find_after_emplace_ok() { + std::unordered_map map; + map.emplace(1, 2); + return map.find(1)->second; +} + +void map_of_sets_find_after_emplace_ok(std::map>& map) { + map.emplace(1, std::set()); + auto it = map.find(1); + it->second.emplace(2); +} + +int set_conditional_insert_empty_ok(bool b) { + std::set set; + if (b) { + set.insert(1); + } + if (!set.empty()) { + return *set.begin(); + } + return 0; +} + +int map_conditional_insert_count_ok(bool b) { + std::map map; + if (b) { + map.emplace(1, 2); + } + if (map.count(1) > 0) { + return map.find(1)->second; + } + return 0; +} + +int list_conditional_insert_size_ok(bool b) { + std::list list; + if (b) { + list.push_back(1); + } + if (list.size() > 0) { + return *list.begin(); + } + return 0; +} + +void insert_one(std::map& map) { map.emplace(1, 2); } + +int map_find_after_callee_insert_ok() { + std::map map; + insert_one(map); + return map.find(1)->second; +} + +int list_copy_back_inserter_ok() { + int a[] = {1, 2}; + std::list list; + std::copy(a, a + 2, std::back_inserter(list)); + return *list.begin(); +} + +int deque_copy_front_inserter_ok() { + int a[] = {1, 2}; + std::deque deque; + std::copy(a, a + 2, std::front_inserter(deque)); + return *deque.begin(); +} + +int set_copy_inserter_ok() { + int a[] = {1, 2}; + std::set set; + std::copy(a, a + 2, std::inserter(set, set.end())); + return *set.begin(); +} + +int map_copy_inserter_find_ok() { + std::pair a[] = {{1, 2}}; + std::map map; + std::copy(a, a + 1, std::inserter(map, map.end())); + return map.find(1)->second; +} + +// references to the elements of node-based containers stay valid across +// insertions, including rehashing +int unordered_map_reference_stability_ok(std::unordered_map& map) { + const int& value = map[1]; + map[2] = 3; + map.emplace(4, 5); + return value; +} + +int list_insert_iterator_ok(std::list& list) { + auto it = list.begin(); + list.push_back(1); + list.push_front(2); + return *it; +} + +void map_erase_loop_ok(std::map& map) { + for (auto it = map.begin(); it != map.end();) { + if (it->second == 0) { + it = map.erase(it); + } else { + ++it; + } + } +} + +void set_erase_postfix_loop_ok(std::set& set) { + for (auto it = set.begin(); it != set.end();) { + if (*it == 0) { + set.erase(it++); + } else { + ++it; + } + } +} + +// issue #1884 +void range_for_delete_list_ok(std::list& list) { + for (int* p : list) { + delete p; + } +} + +struct RefCounted { + void Unref() { delete this; } +}; + +void range_for_unref_map_ok(std::map& map) { + for (auto& entry : map) { + entry.second->Unref(); + } +} + +int map_iterate_ok(const std::map& map) { + int sum = 0; + for (const auto& entry : map) { + sum += entry.second; + } + return sum; +} + +int empty_map_iterate_ok() { + std::map map; + int sum = 0; + for (const auto& entry : map) { + sum += entry.second; + } + return sum; +} + +int list_end_decrement_ok(std::list& list) { + auto it = list.end(); + --it; + return *it; +} + +// insertions at either end of a deque keep references valid +int deque_push_back_reference_ok(std::deque& deque) { + const int& front = deque.front(); + deque.push_back(1); + return front; +} + +int deque_iterator_after_push_back_ok(std::deque& deque) { + deque.push_back(1); + auto it = deque.begin(); + return *it; +} + +// operator< is translated and reads the fields of the iterators, which the +// models do not write +bool deque_iterator_compare_ok(std::deque& deque) { + auto first = deque.begin(); + auto last = deque.end(); + return first < last; +} + +// erase(key) does not say which element is erased +int FN_map_erase_key_reference_bad(std::map& map) { + const int& value = map.at(1); + map.erase(1); + return value; +} + +// the presence of individual keys is not tracked +int FN_map_find_absent_key_bad() { + std::map map; + map[2] = 3; + return map.find(1)->second; +} + +void clear_map(std::map& map) { map.clear(); } + +// clear() in a callee does not know the elements that the caller has seen, so +// it does not invalidate references to them +int FN_call_clear_after_at_reference_bad(std::map& map) { + const int& value = map.at(1); + clear_map(map); + return value; +} + +int begin_value(std::set& set) { return *set.begin(); } + +// the emptiness of a container is only used when it is known in the procedure +// that calls begin() +int FN_call_begin_value_empty_set_bad() { + std::set set; + return begin_value(set); +} + +// what a closure passed by value to an unknown function captures by reference +// is not havocked, so the container is still known to be empty +int FP_set_for_each_insert_ok() { + int a[] = {1, 2}; + std::set set; + std::for_each(a, a + 2, [&set](int x) { set.insert(x); }); + return *set.begin(); +} + +// the end iterator of a list or of a tree-based container stays valid after +// clear(), but clear() invalidates all the iterators in the models +int FP_list_end_after_clear_ok() { + std::list list; + auto end = list.end(); + list.clear(); + list.push_back(1); + --end; + return *end; +} + +int FP_map_end_after_clear_ok() { + std::map map; + auto end = map.end(); + map.clear(); + map[1] = 2; + --end; + return end->second; +} + +struct DerivedMap : std::map {}; + +int derived_map_subscript_ok(DerivedMap& map) { + map[1] = 2; + return map.find(1)->second; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp b/infer/tests/codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp new file mode 100644 index 0000000000..bbf46dc351 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/pulse/std_containers_libstdcxx.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Mirrors how libstdc++ declares std::set and std::list, whose iterator +// classes are not modelled. Do not include C++ standard headers. +namespace std { + +template +struct _Rb_tree_const_iterator { + _Rb_tree_const_iterator& operator++(); + const _Tp& operator*() const; + void* _M_node; +}; + +template +bool operator!=(const _Rb_tree_const_iterator<_Tp>& __x, + const _Rb_tree_const_iterator<_Tp>& __y); + +template +struct set { + typedef _Rb_tree_const_iterator<_Key> iterator; + set(const set& __x); + ~set(); + iterator begin() const; + iterator end() const; + void* _M_impl; +}; + +template +struct list { + ~list(); + _Tp& front(); + void clear(); + void* _M_impl; +}; + +} // namespace std + +int iterate_local_set_bad(const std::set& set) { + std::set local = set; + int sum = 0; + for (std::set::iterator it = local.begin(); it != local.end(); ++it) { + sum += *it; + } + return sum; +} + +int list_front_after_clear_bad(std::list& list) { + int& first = list.front(); + list.clear(); + return first; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/taint/strings.cpp b/infer/tests/codetoanalyze/cpp/pulse/taint/strings.cpp index 254c4e4293..47f4fe56b0 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/taint/strings.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/taint/strings.cpp @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -63,6 +64,22 @@ void memmove_bad() { __infer_taint_sink(copy); } +void strcpy_c_str_of_copy_bad() { + char laundered_source[50]; + auto source = __infer_taint_source(); + std::string copy(source.begin(), source.end()); + strcpy(laundered_source, copy.c_str()); + __infer_taint_sink(laundered_source); +} + +void strcpy_data_of_copy_bad() { + char laundered_source[50]; + auto source = __infer_taint_source(); + std::string copy(source.begin(), source.end()); + strcpy(laundered_source, copy.data()); + __infer_taint_sink(laundered_source); +} + void memchr_ok() { auto source = __infer_taint_source(); auto laundered_source = (char*)memchr(source.c_str(), 'a', 10); @@ -87,6 +104,20 @@ void constructor3_bad() { __infer_taint_sink(laundered_source); } +void constructor4_bad() { + auto source = __infer_taint_source(); + auto laundered_source = std::string(source.begin() + 1, source.end() - 1); + __infer_taint_sink(laundered_source); +} + +void constructor5_bad() { + auto source = __infer_taint_source(); + auto start = std::find(source.begin(), source.end(), ':'); + auto laundered_source = + std::string(start, std::find(start, source.end(), ';')); + __infer_taint_sink(laundered_source); +} + void concat1_bad() { auto source = __infer_taint_source(); source += "other string"; diff --git a/infer/tests/codetoanalyze/cpp/pulse/vector.cpp b/infer/tests/codetoanalyze/cpp/pulse/vector.cpp index fd65cdb82b..666f1ee6b5 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/vector.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/vector.cpp @@ -320,6 +320,153 @@ void emplace_back_bad(std::vector& vec) { std::cout << *elt << "\n"; } +void emplace_no_args_bad(std::vector& vec) { + int* elt = &vec[1]; + vec.emplace(vec.begin()); + std::cout << *elt << "\n"; +} + +void emplace_back_no_args_bad(std::vector& vec) { + int* elt = &vec[1]; + vec.emplace_back(); + std::cout << *elt << "\n"; +} + +void reserve_then_emplace_back_no_args_ok(std::vector& vec) { + vec.reserve(vec.size() + 1); + int* elt = &vec[1]; + vec.emplace_back(); + std::cout << *elt << "\n"; +} + +void erase_bad(std::vector& vec) { + int* elt = &vec[1]; + vec.erase(vec.begin()); + std::cout << *elt << "\n"; +} + +void erase_range_bad(std::vector& vec) { + int* elt = &vec[1]; + vec.erase(vec.begin(), vec.end()); + std::cout << *elt << "\n"; +} + +void resize_bad(std::vector& vec) { + int* elt = &vec[1]; + vec.resize(vec.size() * 2); + std::cout << *elt << "\n"; +} + +void reserve_then_resize_ok(std::vector& vec) { + vec.reserve(vec.size() * 2); + int* elt = &vec[1]; + vec.resize(vec.size() * 2, 7); + std::cout << *elt << "\n"; +} + +// erase invalidates the elements before the erased position too +void FP_erase_last_ok(std::vector& vec) { + int* elt = &vec[0]; + vec.erase(vec.end() - 1); + std::cout << *elt << "\n"; +} + +// erase invalidates the elements before the erased range too +void FP_erase_tail_keep_front_ok(std::vector& vec) { + int& elt = vec.front(); + vec.erase(vec.begin() + 1, vec.end()); + std::cout << elt << "\n"; +} + +// erase invalidates every element even when the range is empty +void FP_erase_empty_range_ok(std::vector& vec) { + int* elt = &vec[0]; + vec.erase(vec.end(), vec.end()); + std::cout << *elt << "\n"; +} + +// the size is unknown, so resize(1) may grow the vector although it has an +// element +void FP_shrinking_resize_ok(std::vector& vec) { + int* elt = &vec[0]; + vec.resize(1); + std::cout << *elt << "\n"; +} + +// the size given to the constructor is not tracked +void FP_shrinking_resize_after_size_constructor_ok() { + std::vector vec(10); + int* elts = vec.data(); + vec.resize(5); + std::cout << elts[0] << "\n"; +} + +void shrinking_resize_ok() { + std::vector vec; + vec.resize(10); + int* elts = vec.data(); + vec.resize(5); + std::cout << elts[0] << "\n"; +} + +void resize_same_size_ok(std::vector& vec) { + int* elt = &vec[1]; + vec.resize(vec.size()); + std::cout << *elt << "\n"; +} + +void assign_range_bad(std::vector& vec, std::vector& vec_other) { + int* elt = &vec[1]; + vec.assign(vec_other.begin(), vec_other.end()); + std::cout << *elt << "\n"; +} + +void insert_range_bad(std::vector& vec, std::vector& vec_other) { + int* elt = &vec[1]; + vec.insert(vec.begin(), vec_other.begin(), vec_other.end()); + std::cout << *elt << "\n"; +} + +void deref_front_after_push_back_bad(std::vector& vec) { + int& elt = vec.front(); + vec.push_back(42); + std::cout << elt << "\n"; +} + +void deref_back_after_clear_bad(std::vector& vec) { + int& elt = vec.back(); + vec.clear(); + std::cout << elt << "\n"; +} + +void deref_data_after_push_back_bad(std::vector& vec) { + int* elts = vec.data(); + vec.push_back(42); + std::cout << elts[1] << "\n"; +} + +// the invalidation is not tracked through pointer arithmetic +void FN_deref_data_offset_after_push_back_bad(std::vector& vec) { + int* elts = vec.data(); + vec.push_back(42); + std::cout << *(elts + 1) << "\n"; +} + +void reserve_then_front_push_back_ok(std::vector& vec) { + vec.reserve(vec.size() + 1); + int& elt = vec.front(); + vec.push_back(42); + std::cout << elt << "\n"; +} + +void push_back_front_ok(std::vector& vec) { vec.push_back(vec.front()); } + +void deref_data_after_resize_ok(std::vector& vec) { + vec.resize(10); + int* elts = vec.data(); + std::cout << elts[1] << "\n"; +} + void f(int&); void push_back_value_ok(std::vector& vec) { @@ -328,6 +475,14 @@ void push_back_value_ok(std::vector& vec) { f(x); } +void copy_front_back_then_push_back_ok(std::vector& vec) { + int x = vec.front(); + int y = vec.back(); + vec.push_back(42); + f(x); + f(y); +} + struct VectorA { int x; @@ -367,3 +522,105 @@ int emplace_back_size_bad() { } return 0; } + +int resize_size_ok() { + std::vector v; + v.resize(3); + if (v.size() != 3) { + int* q = nullptr; + return *q; + } + return 0; +} + +int resize_size_bad() { + std::vector v; + v.resize(3, 42); + if (v.size() == 3) { + int* q = nullptr; + return *q; + } + return 0; +} + +int emplace_size_ok() { + std::vector v; + v.emplace(v.begin(), 42); + if (v.size() != 1) { + int* q = nullptr; + return *q; + } + return 0; +} + +int insert_size_ok() { + std::vector v; + v.insert(v.begin(), 42); + if (v.size() != 1) { + int* q = nullptr; + return *q; + } + return 0; +} + +int insert_size_bad() { + std::vector v; + v.insert(v.begin(), 42); + if (v.size() == 1) { + int* q = nullptr; + return *q; + } + return 0; +} + +int assign_count_size_ok() { + std::vector v; + v.assign(3, 42); + if (v.size() != 3) { + int* q = nullptr; + return *q; + } + return 0; +} + +int assign_count_size_bad() { + std::vector v; + v.assign(3, 42); + if (v.size() == 3) { + int* q = nullptr; + return *q; + } + return 0; +} + +int erase_size_ok() { + std::vector v; + v.push_back(42); + v.erase(v.begin()); + if (!v.empty()) { + int* q = nullptr; + return *q; + } + return 0; +} + +int erase_size_bad() { + std::vector v; + v.push_back(42); + v.erase(v.begin()); + if (v.empty()) { + int* q = nullptr; + return *q; + } + return 0; +} + +int insert_range_size_bad(std::vector& vec_other) { + std::vector v; + v.insert(v.end(), vec_other.begin(), vec_other.end()); + if (!v.empty()) { + int* q = nullptr; + return *q; + } + return 0; +} diff --git a/infer/tests/codetoanalyze/cpp/pulse/vector_iterator.cpp b/infer/tests/codetoanalyze/cpp/pulse/vector_iterator.cpp index 6904355853..03f80a67ec 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/vector_iterator.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/vector_iterator.cpp @@ -83,6 +83,13 @@ void iterator_end_prev_read_ok() { std::cout << *(--iter) << '\n'; } +void iterator_end_prev_next_read_bad(std::vector& vec) { + auto iter = vec.end(); + --iter; + ++iter; + std::cout << *iter << '\n'; +} + void iterator_prev_after_emplace_bad(std::vector& vec) { auto iter = vec.begin(); ++iter; @@ -131,3 +138,251 @@ void iterator_end_returned_ok(std::vector vec, bool b) { return; } } + +void iterator_read_after_erase_bad(std::vector& vec) { + auto iter = vec.begin(); + vec.erase(iter); + std::cout << *iter << '\n'; +} + +void iterator_next_after_erase_bad(std::vector& vec) { + auto iter = vec.begin(); + vec.erase(iter); + ++iter; +} + +void iterator_returned_by_erase_ok(std::vector& vec) { + auto iter = vec.begin(); + iter = vec.erase(iter); + if (iter != vec.end()) { + std::cout << *iter << '\n'; + } +} + +void erase_loop_ok(std::vector& vec) { + for (auto iter = vec.begin(); iter != vec.end();) { + if (*iter == 0) { + iter = vec.erase(iter); + } else { + ++iter; + } + } +} + +// erase invalidates the iterators before the erased position too +void FP_iterator_before_erased_position_read_ok(std::vector& vec) { + auto iter = vec.begin(); + vec.erase(vec.end() - 1); + std::cout << *iter << '\n'; +} + +// comparing iterators does not check that they are still valid +void FN_cached_end_across_erase_bad(std::vector& vec) { + auto end = vec.end(); + for (auto iter = vec.begin(); iter != end;) { + if (*iter == 0) { + iter = vec.erase(iter); + } else { + ++iter; + } + } +} + +// the position returned by erase is unknown +void FN_iterator_returned_by_erase_last_read_bad(std::vector& vec) { + auto iter = vec.erase(vec.end() - 1); + std::cout << *iter << '\n'; +} + +void iterator_returned_by_erase_after_push_back_bad(std::vector& vec) { + auto iter = vec.erase(vec.begin()); + vec.push_back(4); + std::cout << *iter << '\n'; +} + +void iterator_returned_by_insert_ok(std::vector& vec) { + auto iter = vec.begin(); + iter = vec.insert(iter, 4); + std::cout << *iter << '\n'; +} + +void iterator_reassigned_after_push_back_ok(std::vector& vec) { + auto iter = vec.begin(); + vec.push_back(4); + iter = vec.begin(); + std::cout << *iter << '\n'; +} + +void iterator_assigned_then_push_back_bad(std::vector& vec, + std::vector& vec_other) { + auto iter = vec_other.begin(); + iter = vec.begin(); + vec.push_back(4); + std::cout << *iter << '\n'; +} + +struct IteratorElem { + int x; +}; + +int default_iterator_assigned_ok(std::vector& vec) { + std::vector::iterator iter; + iter = vec.begin(); + return iter->x; +} + +int iterator_assign_copies_base_ok(std::vector::iterator iter) { + std::vector::iterator iter_copy; + iter_copy = iter; + if (iter_copy.base() != iter.base()) { + int* q = nullptr; + return *q; + } + return 0; +} + +int iterator_assign_then_advance_ok(std::vector::iterator iter) { + std::vector::iterator iter_copy; + iter_copy = iter; + iter_copy += 1; + if (iter_copy.base() == iter.base()) { + int* q = nullptr; + return *q; + } + return 0; +} + +int iterator_assign_then_next_ok() { + std::vector vec = {1, 2}; + auto iter = vec.begin(); + std::vector::iterator next; + next = iter; + ++next; + *next = 1; + *iter = 0; + if (*next == 0) { + int* q = nullptr; + return *q; + } + return 0; +} + +void iterator_end_prev_then_read_ok() { + std::vector vec = {1, 2}; + auto iter = vec.end(); + --iter; + std::cout << *iter << '\n'; +} + +int iterator_assign_end_then_prev_loop_ok(std::vector& vec) { + int sum = 0; + std::vector::iterator iter; + iter = vec.end(); + while (iter != vec.begin()) { + --iter; + sum += *iter; + } + return sum; +} + +void iterator_end_minus_one_read_ok(std::vector& vec) { + if (vec.empty()) { + return; + } + std::cout << *(vec.end() - 1) << '\n'; +} + +void iterator_end_minus_assign_read_ok(std::vector& vec) { + if (vec.empty()) { + return; + } + auto iter = vec.end(); + iter -= 1; + std::cout << *iter << '\n'; +} + +void iterator_plus_after_push_back_bad(std::vector& vec) { + auto iter = vec.begin() + 1; + vec.push_back(4); + std::cout << *iter << '\n'; +} + +void iterator_plus_assign_after_push_back_bad(std::vector& vec) { + auto iter = vec.begin(); + iter += 1; + vec.push_back(4); + std::cout << *iter << '\n'; +} + +int iterator_plus_base_ok(std::vector::iterator iter) { + if ((iter + 2).base() != iter.base() + 2) { + int* q = nullptr; + return *q; + } + return 0; +} + +int iterator_cbegin_loop_ok(const std::vector& vec) { + int sum = 0; + for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) { + sum += *iter; + } + return sum; +} + +void iterator_cend_read_bad() { + std::vector vec = {1, 2}; + auto iter = vec.cend(); + std::cout << *iter << '\n'; +} + +void iterator_end_plus_zero_read_bad(std::vector& vec) { + std::cout << *(vec.end() + 0) << '\n'; +} + +void iterator_end_minus_then_plus_read_bad(std::vector& vec) { + auto iter = vec.end() - 1; + std::cout << *(iter + 1) << '\n'; +} + +int iterator_plus_minus_assign_round_trip_ok(std::vector& vec) { + auto iter = vec.begin(); + iter += 2; + iter -= 2; + if (iter != vec.begin()) { + int* q = nullptr; + return *q; + } + return 0; +} + +int iterator_plus_same_offset_ok(std::vector& vec) { + if (vec.begin() + 1 != vec.begin() + 1) { + int* q = nullptr; + return *q; + } + return 0; +} + +int iterator_arrow_after_push_back_bad(std::vector& vec) { + auto iter = vec.begin(); + vec.push_back(IteratorElem{1}); + return iter->x; +} + +int iterator_end_arrow_bad(std::vector& vec) { + return vec.end()->x; +} + +struct IteratorNode { + bool defined; +}; + +IteratorNode* iterator_arrow_loop_until_defined_ok( + std::vector>& vec) { + auto iter = vec.begin(); + while (iter != vec.end() && !iter->first->defined) { + ++iter; + } + return iter == vec.end() ? nullptr : iter->second; +} diff --git a/infer/tests/codetoanalyze/java/pulse/NullPointerExceptions.java b/infer/tests/codetoanalyze/java/pulse/NullPointerExceptions.java index 615ae31764..ae35eb0385 100644 --- a/infer/tests/codetoanalyze/java/pulse/NullPointerExceptions.java +++ b/infer/tests/codetoanalyze/java/pulse/NullPointerExceptions.java @@ -781,4 +781,19 @@ void test_capture_alias_good() { } b.x = 0; } + + int derefAfterComparisonToNullBad(A a) { + if (a == null) { + unknownFunc(); + } + return a.x; + } + + int callDerefAfterComparisonToNullWithNullBad() { + return derefAfterComparisonToNullBad(null); + } + + int callDerefAfterComparisonToNullOk() { + return derefAfterComparisonToNullBad(new A()); + } } diff --git a/infer/tests/codetoanalyze/java/pulse/issues.exp b/infer/tests/codetoanalyze/java/pulse/issues.exp index 0b56e4a722..22b24c2a5a 100644 --- a/infer/tests/codetoanalyze/java/pulse/issues.exp +++ b/infer/tests/codetoanalyze/java/pulse/issues.exp @@ -137,6 +137,8 @@ codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.Nu codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.NullPointerExceptions.call_incr_deref2_bad():void, 12, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.NullPointerExceptions.call_incr_deref3_bad():void, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `void NullPointerExceptions.incr_deref3(NullPointerExceptions$A,NullPointerExceptions$A,NullPointerExceptions$A)` here,parameter `a1` of void NullPointerExceptions.incr_deref3(NullPointerExceptions$A,NullPointerExceptions$A,NullPointerExceptions$A),invalid access occurs here] codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.NullPointerExceptions.test_capture_alias_bad():void, 13, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] +codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.NullPointerExceptions.derefAfterComparisonToNullBad(codetoanalyze.java.infer.NullPointerExceptions$A):int, 4, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `a` of int NullPointerExceptions.derefAfterComparisonToNullBad(NullPointerExceptions$A),was compared to null on line 786,invalid access occurs here] +codetoanalyze/java/pulse/NullPointerExceptions.java, codetoanalyze.java.infer.NullPointerExceptions.callDerefAfterComparisonToNullWithNullBad():int, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `int NullPointerExceptions.derefAfterComparisonToNullBad(NullPointerExceptions$A)` here,parameter `a` of int NullPointerExceptions.derefAfterComparisonToNullBad(NullPointerExceptions$A),was compared to null on line 786,invalid access occurs here] codetoanalyze/java/pulse/NullPointerExceptionsMoreTests.java, codetoanalyze.java.infer.NullPointerExceptionsMoreTests.testNullStringDereferencedBad():int, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,assigned,invalid access occurs here] codetoanalyze/java/pulse/NullPointerExceptionsMoreTests.java, codetoanalyze.java.infer.NullPointerExceptionsMoreTests.FN_testParameterRec(codetoanalyze.java.infer.A,int):int, 7, MUTUAL_RECURSION_CYCLE, no_bucket, WARNING, [`int NullPointerExceptionsMoreTests.FN_testParameterRec(A,int)` makes a recursive call to `int NullPointerExceptionsMoreTests.FN_testParameterRec(A,int)`] codetoanalyze/java/pulse/NullPointerExceptionsMoreTests.java, codetoanalyze.java.infer.NullPointerExceptionsMoreTests.FN_testParameterRecBool(codetoanalyze.java.infer.A,boolean):int, 7, MUTUAL_RECURSION_CYCLE, no_bucket, WARNING, [`int NullPointerExceptionsMoreTests.FN_testParameterRecBool(A,boolean)` makes a recursive call to `int NullPointerExceptionsMoreTests.FN_testParameterRecBool(A,boolean)`] diff --git a/infer/tests/codetoanalyze/objc/pulse/issues.exp b/infer/tests/codetoanalyze/objc/pulse/issues.exp index 7391a82a7f..0a974d4590 100644 --- a/infer/tests/codetoanalyze/objc/pulse/issues.exp +++ b/infer/tests/codetoanalyze/objc/pulse/issues.exp @@ -142,6 +142,7 @@ codetoanalyze/objc/pulse/null_deref/dynamic_dispatch.m, DynamicDispatchMain.no_d codetoanalyze/objc/pulse/null_deref/nil_param.m, NilParamNpeBad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,in call to `NilParamA.test:`,parameter `other` of NilParamA.test:,in call to `NilParamA.newObject`,parameter `self` of NilParamA.newObject,a message sent to nil returns nil,return from call to `NilParamA.newObject`,returned,return from call to `NilParamA.test:`,invalid access occurs here] codetoanalyze/objc/pulse/null_deref/return_npe_test.m, MyClass.no_early_return_bad:, 6, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `c` of MyClass.no_early_return_bad:,was compared to null on line 41, column 7,invalid access occurs here] codetoanalyze/objc/pulse/null_deref/return_npe_test.m, MyClass.no_early_return_no_zero_bad:, 6, COMPARED_TO_NULL_AND_DEREFERENCED, no_bucket, ERROR, [compared to null here,parameter `c` of MyClass.no_early_return_no_zero_bad:,was compared to null on line 51, column 7,invalid access occurs here] +codetoanalyze/objc/pulse/null_deref/return_npe_test.m, MyClass.no_early_return_no_zero_manifest_bad, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is assigned to the null pointer,when calling `MyClass.no_early_return_no_zero_bad:` here,parameter `c` of MyClass.no_early_return_no_zero_bad:,was compared to null on line 51, column 7,invalid access occurs here] codetoanalyze/objc/pulse/retain_cycles/BlockInHeap.m, BlockInHeap.assign_strong_handler_to_ivar_bad, 1, RETAIN_CYCLE, no_bucket, ERROR, [assignment of self->_strongHandler part of the trace starts here,parameter `self` of BlockInHeap.assign_strong_handler_to_ivar_bad,when calling `BlockInHeap.setStrongHandler:` here,parameter `self` of BlockInHeap.setStrongHandler:,assigned,self captured by block defined in BlockInHeap.m:30 here,retain cycle here] codetoanalyze/objc/pulse/retain_cycles/BrokenCycles.m, broken_strong_cycle_good_FP, 5, RETAIN_CYCLE, no_bucket, ERROR, [assignment of a_obj->_b part of the trace starts here,allocated by call to `alloc` (modelled),assigned,when calling `ClassA.setB:` here,parameter `self` of ClassA.setB:,assigned,assignment of b_obj->_a part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,when calling `ClassBStrong.setA:` here,parameter `self` of ClassBStrong.setA:,assigned,retain cycle here] codetoanalyze/objc/pulse/retain_cycles/BrokenCycles.m, broken_inner_cycle_good_FP, 5, RETAIN_CYCLE, no_bucket, ERROR, [assignment of b_obj->_a part of the trace starts here,allocated by call to `alloc` (modelled),in call to `NSObject.init` (modelled),assigned,when calling `ClassBStrong.setA:` here,parameter `self` of ClassBStrong.setA:,assigned,assignment of c_obj.a._b part of the trace starts here,allocated by call to `alloc` (modelled),assigned,allocated by call to `alloc` (modelled),in call to `ClassC.setA:`,parameter `self` of ClassC.setA:,parameter `a` of ClassC.setA:,assigned,return from call to `ClassC.setA:`,in call to `ClassC.a`,parameter `self` of ClassC.a,returned,return from call to `ClassC.a`,when calling `ClassA.setB:` here,parameter `self` of ClassA.setB:,assigned,retain cycle here] diff --git a/infer/tests/codetoanalyze/objc/pulse/null_deref/return_npe_test.m b/infer/tests/codetoanalyze/objc/pulse/null_deref/return_npe_test.m index b6efc8613a..65a89e78e3 100644 --- a/infer/tests/codetoanalyze/objc/pulse/null_deref/return_npe_test.m +++ b/infer/tests/codetoanalyze/objc/pulse/null_deref/return_npe_test.m @@ -56,4 +56,8 @@ - (void)no_early_return_no_zero_bad:(ContainerClass*)c { } } +- (void)no_early_return_no_zero_manifest_bad { + [self no_early_return_no_zero_bad:nil]; +} + @end