From 82fd202fa4c417a0be4f09028dfdc88f8d902130 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 8 Jan 2025 18:42:37 +0100 Subject: [PATCH] fix "enforce no trailing \n in Diagnostic_area messages" cannot have an assert in Warning_info::push_warning() because SQL command SIGNAL can set an absolutely arbitrary message, even an empty one or ending with '\n' move the assert into push_warning() and my_message_sql(). followup for 9508a44c3761 --- sql/mysqld.cc | 3 +++ sql/sql_error.cc | 2 +- sql/sql_repl.cc | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 31d9084f235..c48f94e6601 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3077,10 +3077,13 @@ void my_message_sql(uint error, const char *str, myf MyFlags) MyFlags)); DBUG_ASSERT(str != NULL); + DBUG_ASSERT(*str != '\0'); DBUG_ASSERT(error != 0); DBUG_ASSERT((MyFlags & ~(ME_BELL | ME_ERROR_LOG | ME_ERROR_LOG_ONLY | ME_NOTE | ME_WARNING | ME_FATAL)) == 0); + DBUG_ASSERT(str[strlen(str)-1] != '\n'); + if (MyFlags & ME_NOTE) { level= Sql_condition::WARN_LEVEL_NOTE; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index e40a9a70f26..08810755d08 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -692,7 +692,6 @@ Sql_condition *Warning_info::push_warning(THD *thd, const char *msg) { Sql_condition *cond= NULL; - DBUG_ASSERT(msg[strlen(msg)-1] != '\n'); if (! m_read_only) { @@ -750,6 +749,7 @@ void push_warning(THD *thd, Sql_condition::enum_warning_level level, if (level == Sql_condition::WARN_LEVEL_ERROR) level= Sql_condition::WARN_LEVEL_WARN; + DBUG_ASSERT(msg[strlen(msg)-1] != '\n'); (void) thd->raise_condition(code, NULL, level, msg); /* Make sure we also count warnings pushed after calling set_ok_status(). */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 6ad5159737c..2b4b2667fc3 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3086,6 +3086,8 @@ err: } else if (info->errmsg != NULL) safe_strcpy(info->error_text, sizeof(info->error_text), info->errmsg); + else if (info->error_text[0] == 0) + safe_strcpy(info->error_text, sizeof(info->error_text), ER(info->error)); my_message(info->error, info->error_text, MYF(0));