From 246c0b3a353d0831fb00ac4cd46599a33a808d0c Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 10 Jun 2024 12:17:01 +0400 Subject: [PATCH] MDEV-34227 On startup: UBSAN: runtime error: applying non-zero offset in JOIN::make_aggr_tables_info in sql/sql_select.cc Avoid undefined behaviour (applying offset to nullptr). The reported scenario is covered in mysql-test/connect-no-db.test No new tests needed. --- sql/sql_select.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 215a7113b71..b99ea744ae8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3325,7 +3325,8 @@ bool JOIN::make_aggr_tables_info() { List *curr_all_fields= &all_fields; List *curr_fields_list= &fields_list; - JOIN_TAB *curr_tab= join_tab + const_tables; + // Avoid UB (applying .. offset to nullptr) when join_tab is nullptr + JOIN_TAB *curr_tab= join_tab ? join_tab + const_tables : nullptr; TABLE *exec_tmp_table= NULL; bool distinct= false; bool keep_row_order= false; @@ -3883,9 +3884,9 @@ bool JOIN::make_aggr_tables_info() - duplicate value removal Both of these operations are done after window function computation step. */ - curr_tab= join_tab + total_join_tab_cnt(); if (select_lex->window_funcs.elements) { + curr_tab= join_tab + total_join_tab_cnt(); if (!(curr_tab->window_funcs_step= new Window_funcs_computation)) DBUG_RETURN(true); if (curr_tab->window_funcs_step->setup(thd, &select_lex->window_funcs,