From 7244a4d646a2773f39ddc46fa31fbac5a90e8665 Mon Sep 17 00:00:00 2001 From: hadeer Date: Sun, 1 Feb 2026 23:02:10 +0200 Subject: [PATCH 1/3] MDEV-37952: Fix crash when setting mroonga_default_tokenizer to NULL Setting mroonga_default_tokenizer to NULL caused a server crash because the update function did not handle the NULL value before passing it to strcmp. Handle NULL values by treating them as "off" to allow safe variable reset. --- storage/mroonga/ha_mroonga.cpp | 3 +++ .../storage/r/variable_default_tokenizer_disable.result | 5 +++++ .../storage/t/variable_default_tokenizer_disable.test | 7 +++++++ 3 files changed, 15 insertions(+) create mode 100644 storage/mroonga/mysql-test/mroonga/storage/r/variable_default_tokenizer_disable.result create mode 100644 storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp index 3a85eaf18cd50..eab8d8ee3960b 100644 --- a/storage/mroonga/ha_mroonga.cpp +++ b/storage/mroonga/ha_mroonga.cpp @@ -938,6 +938,9 @@ static void mrn_default_tokenizer_update(THD *thd, struct st_mysql_sys_var *var, char **old_value_ptr = (char **)var_ptr; grn_ctx *ctx = &mrn_ctx; + if(!new_value) { + new_value = "off"; + } mrn_change_encoding(ctx, system_charset_info); if (strcmp(*old_value_ptr, new_value) == 0) { GRN_LOG(ctx, GRN_LOG_NOTICE, diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_default_tokenizer_disable.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_default_tokenizer_disable.result new file mode 100644 index 0000000000000..45f1c7adddf39 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_default_tokenizer_disable.result @@ -0,0 +1,5 @@ +SET GLOBAL mroonga_default_tokenizer = NULL; +SHOW GLOBAL VARIABLES LIKE 'mroonga_default_tokenizer'; +Variable_name Value +mroonga_default_tokenizer off +SET GLOBAL mroonga_default_tokenizer = DEFAULT; diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test new file mode 100644 index 0000000000000..3fd993e4bb593 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test @@ -0,0 +1,7 @@ +--source ../../include/mroonga/have_mroonga.inc + +SET GLOBAL mroonga_default_tokenizer = NULL; +SHOW GLOBAL VARIABLES LIKE 'mroonga_default_tokenizer'; +SET GLOBAL mroonga_default_tokenizer = DEFAULT; + +--source ../../include/mroonga/have_mroonga_deinit.inc From 003fc4fdde5d369c0630feba26a12f2ed98499a9 Mon Sep 17 00:00:00 2001 From: hadeer Date: Sat, 7 Feb 2026 13:24:34 +0200 Subject: [PATCH 2/3] mroonga: handle allocation for new_value in mrn_default_tokenizer_update Align with existing mroonga memory management patterns to ensure consistency, rather than relying on the MariaDB framework default behavior. --- storage/mroonga/ha_mroonga.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp index eab8d8ee3960b..5db9aa0b5847d 100644 --- a/storage/mroonga/ha_mroonga.cpp +++ b/storage/mroonga/ha_mroonga.cpp @@ -940,6 +940,9 @@ static void mrn_default_tokenizer_update(THD *thd, struct st_mysql_sys_var *var, if(!new_value) { new_value = "off"; +#ifndef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR + new_value = mrn_my_strdup(new_value, MYF(MY_WME)); +#endif } mrn_change_encoding(ctx, system_charset_info); if (strcmp(*old_value_ptr, new_value) == 0) { From 0c5fa1660c57df1fe94dff72bb34b82b404b2400 Mon Sep 17 00:00:00 2001 From: hadeer Date: Mon, 9 Feb 2026 19:50:23 +0200 Subject: [PATCH 3/3] Mroonga: Refactor variable_default_tokenizer_disable test Add copyright header to the test file. Disable the test in embedded mode by sourcing include/not_embedded.inc." --- .../t/variable_default_tokenizer_disable.test | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test index 3fd993e4bb593..63df372f3faae 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_default_tokenizer_disable.test @@ -1,3 +1,21 @@ +# -*- mode: sql; sql-product: mysql -*- +# +# Copyright (C) 2026 hadeer +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +--source include/not_embedded.inc --source ../../include/mroonga/have_mroonga.inc SET GLOBAL mroonga_default_tokenizer = NULL;