Skip to content

Commit

Permalink
Merge pull request #1335 from goblint/issue-1249
Browse files Browse the repository at this point in the history
Fix `NullPtr` assignment crash in relation analysis
  • Loading branch information
sim642 authored Jan 25, 2024
2 parents 71e21b2 + 0c72edd commit c0e151d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/analyses/apron/relationAnalysis.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ struct
{st' with rel = rel''}
)
| (Mem v, NoOffset) ->
begin match ask.f (Queries.MayPointTo v) with
| ad when Queries.AD.is_top ad -> st
| ad ->
let mvals = Queries.AD.to_mval ad in
let ass' = List.map (fun mval -> assign_to_global_wrapper ask getg sideg st (ValueDomain.Addr.Mval.to_cil mval) f) mvals in
List.fold_right D.join ass' (D.bot ())
end
let ad = ask.f (Queries.MayPointTo v) in
Queries.AD.fold (fun addr acc ->
match addr with
| ValueDomain.Addr.Addr mval ->
D.join acc (assign_to_global_wrapper ask getg sideg st (ValueDomain.Addr.Mval.to_cil mval) f)
| UnknownPtr | NullPtr | StrPtr _ ->
D.join acc st (* Ignore assign *)
) ad (D.bot ())
(* Ignoring all other assigns *)
| _ ->
st
Expand Down Expand Up @@ -381,6 +382,8 @@ struct
if M.tracing then M.tracel "combine" "relation f: %a\n" CilType.Varinfo.pretty f.svar;
if M.tracing then M.tracel "combine" "relation formals: %a\n" (d_list "," CilType.Varinfo.pretty) f.sformals;
if M.tracing then M.tracel "combine" "relation args: %a\n" (d_list "," d_exp) args;
if M.tracing then M.tracel "combine" "relation st: %a\n" D.pretty st;
if M.tracing then M.tracel "combine" "relation fun_st: %a\n" D.pretty fun_st;
let new_fun_rel = RD.add_vars fun_st.rel (RD.vars st.rel) in
let arg_substitutes =
let filter_actuals (x,e) =
Expand Down
10 changes: 10 additions & 0 deletions tests/regression/46-apron2/58-issue-1249.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SKIP PARAM: --set ana.activated[+] apron
int *a;
int b;
void c(int d) {
// *a is a null pointer here, so we should warn but maybe not crash
*a = d;
}
int main() {
c(b);
}

0 comments on commit c0e151d

Please sign in to comment.