Skip to content
Snippets Groups Projects
Commit 738ceae6 authored by Thibault Martin's avatar Thibault Martin Committed by Virgile Prevosto
Browse files

Check if array length is too large in cabs2cil

parent d8829739
No related branches found
No related tags found
No related merge requests found
...@@ -4794,9 +4794,28 @@ and doType (ghost:bool) isFuncArg ...@@ -4794,9 +4794,28 @@ and doType (ghost:bool) isFuncArg
let cst = constFold true len' in let cst = constFold true len' in
(match cst.enode with (match cst.enode with
| Const(CInt64(i, _, _)) -> | Const(CInt64(i, _, _)) ->
if Integer.lt i Integer.zero then begin
Kernel.error ~once:true ~current:true if Integer.lt i Integer.zero then
"Array length is negative." Kernel.error ~once:true ~current:true
"Array length is negative."
else
try
(* Check if array length is > SIZE_MAX / sizeof(bt) *)
let elem_size = Integer.of_int @@ bytesSizeOf bt in
let size_t = bitsSizeOfInt theMachine.kindOfSizeOf in
let size_max = Cil.max_unsigned_number size_t in
let limit = Integer.c_div size_max elem_size in
if Integer.gt i limit then
Kernel.error ~once:true ~current:true
"Array length is too large.";
with
| SizeOfError (msg,_) ->
Kernel.abort ~current:true "%s" msg
| Invalid_argument msg ->
Kernel.fatal ~current:true "%s" msg
| Division_by_zero ->
Kernel.fatal ~current:true "Array element size cannot be zero"
end
| _ when not allowVarSizeArrays -> | _ when not allowVarSizeArrays ->
if isConstant cst then if isConstant cst then
(* e.g., there may be a float constant involved. (* e.g., there may be a float constant involved.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment