mirror of
https://github.com/json-c/json-c.git
synced 2026-04-09 07:19:06 +08:00
Protect array_list_del_idx against size_t overflow.
If the assignment of stop overflows due to idx and count being larger than SIZE_T_MAX in sum, out of boundary access could happen. It takes invalid usage of this function for this to happen, but I decided to add this check so array_list_del_idx is as safe against bad usage as the other arraylist functions.
This commit is contained in:
@@ -136,6 +136,9 @@ int array_list_del_idx(struct array_list *arr, size_t idx, size_t count)
|
|||||||
{
|
{
|
||||||
size_t i, stop;
|
size_t i, stop;
|
||||||
|
|
||||||
|
/* Avoid overflow in calculation with large indices. */
|
||||||
|
if (idx > SIZE_T_MAX - count)
|
||||||
|
return -1;
|
||||||
stop = idx + count;
|
stop = idx + count;
|
||||||
if (idx >= arr->length || stop > arr->length)
|
if (idx >= arr->length || stop > arr->length)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user