From dca2e5509e38adca8fec18dbb9c330defbe9f131 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 4 Apr 2025 16:22:30 +1100 Subject: [PATCH] MDEV-36480 USAN: checking identifier names for 0 length names Identifier names can be empty in the grammar. The check_ident_length is used from everything from triggers, to partitions, to key names and UDF names. This change updates 0 length identifiers as valid without further checking. Primary keys are one clear case where a empty name is used and the name.str is a null pointer. Checking empty names where the key->name.str is a null pointer results in a UBSAN error in Well_formed_prefix_status further down the stack which we can avoid. --- sql/sql_parse.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 62bb759b3f3..54f08132c1c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -10389,7 +10389,13 @@ bool check_string_char_length(const LEX_CSTRING *str, uint err_msg, bool check_ident_length(const LEX_CSTRING *ident) { - if (check_string_char_length(ident, 0, NAME_CHAR_LEN, system_charset_info, 1)) + /* + string_char_length desite the names, goes into Well_formed_prefix_status + so this is more than just a length comparison. Things like a primary key + doesn't have a name, therefore no length. Also the ident grammar allows + empty backtick. Check quickly the length, and if 0, accept that. + */ + if (ident->length && check_string_char_length(ident, 0, NAME_CHAR_LEN, system_charset_info, 1)) { my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str); return 1;