Skip to content

Commit

Permalink
MDEV-26350: select_lex->ref_pointer_array.size() % 5 == 0
Browse files Browse the repository at this point in the history
Due to an integer overflow an invalid size of ref_pointer_array could be
allocated.

Using size_t allows this continue. Allocation failures are
handled gracefully if the value is too big.

Thanks to Zuming Jiang for the bug report and fuzzing MariaDB.

Reviewer: Sanja
  • Loading branch information
grooverdan committed Aug 18, 2021
1 parent f73eea4 commit 0dec71c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2698,15 +2698,16 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
prepared statement
*/
Query_arena *arena= thd->stmt_arena;
const uint n_elems= (n_sum_items +
const size_t n_elems= (n_sum_items +
n_child_sum_items +
item_list.elements +
select_n_reserved +
select_n_having_items +
select_n_where_fields +
order_group_num +
hidden_bit_fields +
fields_in_window_functions) * 5;
fields_in_window_functions) * (size_t) 5;
DBUG_ASSERT(n_elems % 5 == 0);
if (!ref_pointer_array.is_null())
{
/*
Expand Down

0 comments on commit 0dec71c

Please sign in to comment.