-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bufferoverrun Analysis - small fixes and improvements #1736
base: main
Are you sure you want to change the base?
Changes from all commits
31ab607
fd0a4e6
347d391
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -347,6 +347,10 @@ module ArrayAccessCondition = struct | |||||||
Bound.is_not_infty (ItvPure.ub real_idx) && Bound.le (ItvPure.ub size) (ItvPure.ub real_idx) | ||||||||
then {report_issue_type= Issue IssueType.buffer_overrun_l2; propagate= false} | ||||||||
(* symbolic il >= sl, probably an error *) | ||||||||
else if | ||||||||
Bound.is_infty (ItvPure.ub real_idx) && Bound.is_not_infty (ItvPure.ub size) | ||||||||
then {report_issue_type= Issue IssueType.buffer_overrun_l3; propagate= false} | ||||||||
(* su < iu = +oo, probably an error *) | ||||||||
Comment on lines
+350
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For the example case, it reports L4 issue as above. The reason you did not see the issue is that it suppresses the issue types that are likely to be false positive, e.g. offset or size interval includes an infinity bound like above. infer/infer/src/base/IssueType.ml Lines 380 to 382 in 5aeb169
Note that ~enabled:false is given when defining the L4 issue type.
To enable all issue types, you can pass |
||||||||
else if | ||||||||
Bound.is_symbolic (ItvPure.lb real_idx) && Bound.le (ItvPure.lb size) (ItvPure.lb real_idx) | ||||||||
then {report_issue_type= Issue IssueType.buffer_overrun_s2; propagate= true} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ module Sem = BufferOverrunSemantics | |
module Trace = BufferOverrunTrace | ||
module TraceSet = Trace.Set | ||
module TypModels = BufferOverrunTypModels | ||
module BoField = BufferOverrunField | ||
|
||
module ModelEnv = struct | ||
type model_env = | ||
|
@@ -52,14 +53,37 @@ module Exec = struct | |
mem | ||
|
||
|
||
let rec decl_local_loc ({tenv} as model_env) loc typ ~inst_num ~represents_multiple_values | ||
let rec decl_local_struct_fields_loc: ModelEnv.model_env -> Loc.t -> Struct.fields -> Dom.Mem.t * int -> Dom.Mem.t * int = | ||
fun model_env loc fields (mem, inst_num) -> | ||
match fields with | ||
| field :: tl -> ( | ||
match field with | ||
| (fn, typ, _) -> ( | ||
match typ.desc with | ||
| Tarray {elt= _; length; stride} -> | ||
let child_loc = BoField.Field {prefix= loc; fn; typ = (Some typ)} in | ||
let stride = Option.map ~f:IntLit.to_int_exn stride in | ||
let (mem, inst_num) = decl_local_array model_env child_loc typ ~length ?stride ~inst_num | ||
~represents_multiple_values:false ~dimension:1 mem | ||
in | ||
decl_local_struct_fields_loc model_env loc tl (mem, inst_num) | ||
| _ -> decl_local_struct_fields_loc model_env loc tl (mem, inst_num))) | ||
| [] -> (mem, inst_num) | ||
and decl_local_loc ({tenv} as model_env) loc typ ~inst_num ~represents_multiple_values | ||
~dimension mem = | ||
match typ.Typ.desc with | ||
| Typ.Tarray {elt= typ; length; stride} -> | ||
let stride = Option.map ~f:IntLit.to_int_exn stride in | ||
decl_local_array model_env loc typ ~length ?stride ~inst_num ~represents_multiple_values | ||
~dimension mem | ||
| Typ.Tstruct typname -> ( | ||
let mem = ( | ||
match Tenv.lookup tenv typname with | ||
| Some {fields} -> | ||
let (mem, _) = decl_local_struct_fields_loc model_env loc fields (mem, 1) in mem | ||
| None -> mem | ||
) | ||
in | ||
Comment on lines
+80
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to pass current
|
||
match TypModels.dispatch tenv typname with | ||
| Some (CArray {element_typ; length}) -> | ||
decl_local_array model_env loc element_typ ~length:(Some length) ~inst_num | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While
MinMaxB
was introduced to express more complex min/max expressions, it is NOT always a better choice than others. By its complex nature, many operations may easily lose precision onMinMaxB
bound, for example, during widening it is more likely to have infinity bounds according to my experience. Therefore, if we want to introduceMinMaxB
here for the plus operation, we should evaluate overall precision impacts. Let me check if it is fine for our use cases.