From 58742cf40858e0c747fda5c8cc54a1b19b4f2629 Mon Sep 17 00:00:00 2001 From: Martin Alderete Date: Tue, 13 Feb 2024 20:03:04 +0100 Subject: [PATCH] Improved the way my_plugin_log_message() handles plugin_ptr argument. This patch, helps MySQL to be more resilient and prevent crashes when plugins misbehave and use the function "my_plugin_log_message" with a "nullptr". Also, with this patch MySQL will not crash, instead it will log a message telling it received and unexpected nullptr and does a best-effort to log original plugin's message. --- sql/log.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sql/log.cc b/sql/log.cc index 50bd3d1788d0..1f35d4b1836a 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2355,8 +2355,15 @@ int my_plugin_log_message(MYSQL_PLUGIN *plugin_ptr, plugin_log_level level, return 1; } + std::string plugin_name; + if (plugin) { + plugin_name = plugin->name.str; + } else { + plugin_name = "'Unknown' (plugin_ptr parameter has unexpected nullptr)"; + } + snprintf(format2, sizeof(format2) - 1, "Plugin %.*s reported: '%s'", - (int)plugin->name.length, plugin->name.str, format); + (int)plugin_name.length(), plugin_name.c_str(), format); va_start(args, format); vsnprintf(msg, sizeof(msg) - 1, format2, args); @@ -2373,7 +2380,7 @@ int my_plugin_log_message(MYSQL_PLUGIN *plugin_ptr, plugin_log_level level, richer (service) interface can use that to add such information. */ - .component(plugin->name.str) + .component(plugin_name.c_str()) .verbatim(msg); return 0;