Skip to content

Commit 50f3cfa

Browse files
authored
Merge pull request #1838 from Robotechnic/checks
Add Mopsa checks JSON output for dashboard
2 parents 3988737 + 3266e4d commit 50f3cfa

File tree

15 files changed

+411
-95
lines changed

15 files changed

+411
-95
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ gobview_out/*
9191
witness.yml
9292
witness.certificate.yml
9393

94+
# checks
95+
checks.json
96+
9497
# transformations
9598
transformed.c
9699

src/analyses/assert.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ struct
2323
match Queries.eval_bool (Analyses.ask_of_man man) e with
2424
| `Lifted false ->
2525
assert_msg Error "Assertion \"%a\" will fail." CilType.Exp.pretty e;
26+
Checks.error Checks.Category.AssertionFailure "Assertion \"%a\" will fail." CilType.Exp.pretty e;
2627
if refine then raise Analyses.Deadcode else man.local
2728
| `Lifted true ->
2829
assert_msg Success "Assertion \"%a\" will succeed" CilType.Exp.pretty e;
30+
Checks.safe_msg Checks.Category.AssertionFailure "Assertion \"%a\" will succeed" CilType.Exp.pretty e;
2931
man.local
3032
| `Bot ->
3133
M.error ~category:Assert "Assertion \"%a\" produces a bottom. What does that mean? (currently uninitialized arrays' content is bottom)" CilType.Exp.pretty e;
34+
Checks.error Checks.Category.AssertionFailure "Assertion \"%a\" produces a bottom. What does that mean? (currently uninitialized arrays' content is bottom)" CilType.Exp.pretty e;
3235
man.local
3336
| `Top ->
3437
assert_msg Warning "Assertion \"%a\" is unknown." CilType.Exp.pretty e;
38+
Checks.warn Checks.Category.AssertionFailure "Assertion \"%a\" is unknown." CilType.Exp.pretty e;
3539
man.local
3640

3741
let special man (lval: lval option) (f:varinfo) (args:exp list) : D.t =

src/analyses/base.ml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,25 @@ struct
202202
fun x y ->
203203
(match ID.equal_to Z.zero y with
204204
| `Eq ->
205-
M.error ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of division is zero"
205+
M.error ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of division is zero";
206+
Checks.error Checks.Category.DivisionByZero "Second argument of division is zero"
206207
| `Top ->
207-
M.warn ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of division might be zero"
208-
| `Neq -> ());
208+
M.warn ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of division might be zero";
209+
Checks.warn Checks.Category.DivisionByZero "Second argument of division might be zero"
210+
| `Neq ->
211+
Checks.safe Checks.Category.DivisionByZero);
209212
ID.div x y
210213
| Mod ->
211214
fun x y ->
212215
(match ID.equal_to Z.zero y with
213216
| `Eq ->
214-
M.error ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of modulo is zero"
217+
M.error ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of modulo is zero";
218+
Checks.error Checks.Category.DivisionByZero "Second argument of modulo is zero"
215219
| `Top ->
216-
M.warn ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of modulo might be zero"
217-
| `Neq -> ());
220+
M.warn ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Second argument of modulo might be zero";
221+
Checks.warn Checks.Category.DivisionByZero "Second argument of modulo might be zero"
222+
| `Neq ->
223+
Checks.safe Checks.Category.DivisionByZero);
218224
ID.rem x y
219225
| Lt -> ID.lt
220226
| Gt -> ID.gt
@@ -1092,19 +1098,24 @@ struct
10921098
(
10931099
if AD.is_null adr then (
10941100
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
1095-
M.error ~category:M.Category.Behavior.Undefined.nullpointer_dereference ~tags:[CWE 476] "Must dereference NULL pointer"
1101+
M.error ~category:M.Category.Behavior.Undefined.nullpointer_dereference ~tags:[CWE 476] "Must dereference NULL pointer";
1102+
Checks.error Checks.Category.InvalidMemoryAccess "Must dereference NULL pointer"
10961103
)
10971104
else if AD.may_be_null adr then (
10981105
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
1099-
M.warn ~category:M.Category.Behavior.Undefined.nullpointer_dereference ~tags:[CWE 476] "May dereference NULL pointer"
1106+
M.warn ~category:M.Category.Behavior.Undefined.nullpointer_dereference ~tags:[CWE 476] "May dereference NULL pointer";
1107+
Checks.warn Checks.Category.InvalidMemoryAccess "May dereference NULL pointer"
1108+
) else (
1109+
Checks.safe Checks.Category.InvalidMemoryAccess
11001110
);
11011111
(* Warn if any of the addresses contains a non-local and non-global variable *)
11021112
if AD.exists (function
11031113
| AD.Addr.Addr (v, _) -> not (CPA.mem v st.cpa) && not (is_global (Analyses.ask_of_man man) v)
11041114
| _ -> false
11051115
) adr then (
11061116
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
1107-
M.warn "lval %a points to a non-local variable. Invalid pointer dereference may occur" d_lval lval
1117+
M.warn "lval %a points to a non-local variable. Invalid pointer dereference may occur" d_lval lval;
1118+
Checks.warn Checks.Category.InvalidMemoryAccess "lval %a points to a non-local variable. Invalid pointer dereference may occur" d_lval lval
11081119
)
11091120
);
11101121
AD.map (add_offset_varinfo (convert_offset ~man st ofs)) adr
@@ -1176,10 +1187,11 @@ struct
11761187
let eval_funvar man fval: Queries.AD.t =
11771188
let fp = eval_fv ~man man.local fval in
11781189
if AD.is_top fp then (
1179-
if AD.cardinal fp = 1 then
1180-
M.warn ~category:Imprecise ~tags:[Category Call] "Unknown call to function %a." d_exp fval
1181-
else
1182-
M.warn ~category:Imprecise ~tags:[Category Call] "Function pointer %a may contain unknown functions." d_exp fval
1190+
if AD.cardinal fp = 1 then (
1191+
M.warn ~category:Imprecise ~tags:[Category Call] "Unknown call to function %a." d_exp fval;
1192+
) else (
1193+
M.warn ~category:Imprecise ~tags:[Category Call] "Function pointer %a may contain unknown functions." d_exp fval;
1194+
)
11831195
);
11841196
fp
11851197

@@ -2223,7 +2235,9 @@ struct
22232235
end
22242236

22252237
let special_unknown_invalidate man f args =
2226-
(if CilType.Varinfo.equal f dummyFunDec.svar then M.warn ~category:Imprecise ~tags:[Category Call] "Unknown function ptr called");
2238+
(if CilType.Varinfo.equal f dummyFunDec.svar then (
2239+
M.warn ~category:Imprecise ~tags:[Category Call] "Unknown function ptr called";
2240+
));
22272241
let desc = LF.find f in
22282242
let shallow_addrs = LibraryDesc.Accesses.find desc.accs { kind = Write; deep = false } args in
22292243
let deep_addrs = LibraryDesc.Accesses.find desc.accs { kind = Write; deep = true } args in
@@ -2259,17 +2273,23 @@ struct
22592273
| Address a ->
22602274
if AD.is_top a then (
22612275
AnalysisStateUtil.set_mem_safety_flag InvalidFree;
2262-
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Points-to set for pointer %a in function %s is top. Potentially invalid memory deallocation may occur" d_exp ptr special_fn.vname
2276+
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Points-to set for pointer %a in function %s is top. Potentially invalid memory deallocation may occur" d_exp ptr special_fn.vname;
2277+
Checks.warn Checks.Category.InvalidMemoryAccess "Points-to set for pointer %a in function %s is top. Potentially invalid memory deallocation may occur" d_exp ptr special_fn.vname
22632278
) else if has_non_heap_var a then (
22642279
AnalysisStateUtil.set_mem_safety_flag InvalidFree;
2265-
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Free of non-dynamically allocated memory in function %s for pointer %a" special_fn.vname d_exp ptr
2280+
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Free of non-dynamically allocated memory in function %s for pointer %a" special_fn.vname d_exp ptr;
2281+
Checks.warn Checks.Category.InvalidMemoryAccess "Free of non-dynamically allocated memory in function %s for pointer %a" special_fn.vname d_exp ptr
22662282
) else if has_non_zero_offset a then (
22672283
AnalysisStateUtil.set_mem_safety_flag InvalidFree;
2268-
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 761] "Free of memory not at start of buffer in function %s for pointer %a" special_fn.vname d_exp ptr
2284+
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 761] "Free of memory not at start of buffer in function %s for pointer %a" special_fn.vname d_exp ptr;
2285+
Checks.warn Checks.Category.InvalidMemoryAccess "Free of memory not at start of buffer in function %s for pointer %a" special_fn.vname d_exp ptr
2286+
) else (
2287+
Checks.safe Checks.Category.InvalidMemoryAccess
22692288
)
22702289
| _ ->
22712290
AnalysisStateUtil.set_mem_safety_flag InvalidFree;
2272-
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Pointer %a in function %s doesn't evaluate to a valid address. Invalid memory deallocation may occur" d_exp ptr special_fn.vname
2291+
M.warn ~category:(Behavior (Undefined InvalidMemoryDeallocation)) ~tags:[CWE 590] "Pointer %a in function %s doesn't evaluate to a valid address. Invalid memory deallocation may occur" d_exp ptr special_fn.vname;
2292+
Checks.warn Checks.Category.InvalidMemoryAccess "Pointer %a in function %s doesn't evaluate to a valid address. Invalid memory deallocation may occur" d_exp ptr special_fn.vname
22732293

22742294
let points_to_heap_only man ptr =
22752295
match man.ask (Queries.MayPointTo ptr) with
@@ -2327,6 +2347,7 @@ struct
23272347
end
23282348
| _ ->
23292349
(M.warn "Pointer %a has a points-to-set of top. An invalid memory access might occur" d_exp ptr;
2350+
Checks.warn Checks.Category.InvalidMemoryAccess "Pointer %a has a points-to-set of top. An invalid memory access might occur" d_exp ptr;
23302351
`Top)
23312352

23322353
let special man (lv:lval option) (f: varinfo) (args: exp list) =

src/analyses/baseInvariant.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,11 @@ struct
293293
let warn_and_top_on_zero x =
294294
if GobOption.exists (Z.equal Z.zero) (ID.to_int x) then
295295
(M.error ~category:M.Category.Integer.div_by_zero ~tags:[CWE 369] "Must Undefined Behavior: Second argument of div or mod is 0, continuing with top";
296+
Checks.error Checks.Category.DivisionByZero "Must Undefined Behavior: Second argument of div or mod is 0, continuing with top";
296297
ID.top_of ikind)
297-
else
298-
x
298+
else (
299+
Checks.safe Checks.Category.DivisionByZero;
300+
x)
299301
in
300302
let meet_bin a' b' = id_meet_down ~old:a ~c:a', id_meet_down ~old:b ~c:b' in
301303
let meet_com oi = (* commutative *)

0 commit comments

Comments
 (0)