From db5bb6f3339be5a49c0f397eb80a0f259f73f447 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 3 Apr 2025 18:29:24 +1100 Subject: [PATCH] MDEV-36469 don't check is_infoschema_db for null db The is_infoschema_db is a deep character set based comparision. In in many cases the db is still an empty structure. Doing this comparion early prevents a UBSAN error by not performing character set operations on a null pointer. --- sql/lex_ident.h | 2 +- sql/sql_parse.cc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/lex_ident.h b/sql/lex_ident.h index e5b6bf3f970..f447942ad30 100644 --- a/sql/lex_ident.h +++ b/sql/lex_ident.h @@ -165,6 +165,7 @@ public: */ class Lex_ident_db: public Lex_ident_fs { +public: bool is_null() const { return length == 0 && str == NULL; @@ -174,7 +175,6 @@ class Lex_ident_db: public Lex_ident_fs { return length == 0 && str != NULL; } -public: static bool check_name(const LEX_CSTRING &str); static bool check_name_with_error(const LEX_CSTRING &str); public: diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b18cf0a1076..85faa44c96b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -8111,7 +8111,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, DBUG_RETURN(0); else fqtn= FALSE; - bool info_schema= is_infoschema_db(&db); + bool info_schema= (db.is_null() || db.is_empty()) + ? false : is_infoschema_db(&db); if (!table->sel && info_schema && (table_options & TL_OPTION_UPDATING) && /* Special cases which are processed by commands itself */