Skip to content

Commit

Permalink
Warn if lval contains an address with a non-local var
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Oct 4, 2023
1 parent 055d9cc commit 2c883eb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,18 @@ struct
else if AD.may_be_null adr then (
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.warn ~category:M.Category.Behavior.Undefined.nullpointer_dereference ~tags:[CWE 476] "May dereference NULL pointer"
)
);
(* Warn if any of the addresses contains a non-local variable *)
AD.iter (function
| AD.Addr.Addr (v,o) ->
if not @@ CPA.mem v st.cpa then (
(* TODO: Not the smartest move to set the global flag within an iter *)
(* TODO: We can resort to using AD.exists instead *)
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.warn "lval %a points to non-local variable %a. Invalid pointer dereference may occur" d_lval lval CilType.Varinfo.pretty v
)
| _ -> ()
) adr
);
AD.map (add_offset_varinfo (convert_offset a gs st ofs)) adr
| _ ->
Expand Down

0 comments on commit 2c883eb

Please sign in to comment.