mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-15 08:46:18 +01:00
Merge branch 'wip/chergert/garray-bail' into 'master'
garray: add overflow checks before expanding array See merge request GNOME/glib!195
This commit is contained in:
commit
3cafd7f266
@ -803,7 +803,13 @@ static void
|
|||||||
g_array_maybe_expand (GRealArray *array,
|
g_array_maybe_expand (GRealArray *array,
|
||||||
guint len)
|
guint len)
|
||||||
{
|
{
|
||||||
guint want_alloc = g_array_elt_len (array, array->len + len +
|
guint want_alloc;
|
||||||
|
|
||||||
|
/* Detect potential overflow */
|
||||||
|
if G_UNLIKELY ((G_MAXUINT - array->len) < len)
|
||||||
|
g_error ("adding %u to array would overflow", len);
|
||||||
|
|
||||||
|
want_alloc = g_array_elt_len (array, array->len + len +
|
||||||
array->zero_terminated);
|
array->zero_terminated);
|
||||||
|
|
||||||
if (want_alloc > array->alloc)
|
if (want_alloc > array->alloc)
|
||||||
@ -1162,6 +1168,10 @@ static void
|
|||||||
g_ptr_array_maybe_expand (GRealPtrArray *array,
|
g_ptr_array_maybe_expand (GRealPtrArray *array,
|
||||||
gint len)
|
gint len)
|
||||||
{
|
{
|
||||||
|
/* Detect potential overflow */
|
||||||
|
if G_UNLIKELY ((G_MAXUINT - array->len) < len)
|
||||||
|
g_error ("adding %u to array would overflow", len);
|
||||||
|
|
||||||
if ((array->len + len) > array->alloc)
|
if ((array->len + len) > array->alloc)
|
||||||
{
|
{
|
||||||
guint old_alloc = array->alloc;
|
guint old_alloc = array->alloc;
|
||||||
|
Loading…
Reference in New Issue
Block a user