Commit 383d53ed authored by Sutou Kouhei's avatar Sutou Kouhei Committed by Daniel Black

MDEV-21166 Add Mroonga initialized check to Mroonga UDFs

Mroonga UDFs can't be used without loading Mroonga.
parent 49dff5a4
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include "mrn.hpp"
#include "mrn_mysql.h" #include "mrn_mysql.h"
#include "mrn_mysql_compat.h" #include "mrn_mysql_compat.h"
...@@ -296,6 +297,7 @@ static PSI_mutex_info mrn_mutexes[] = ...@@ -296,6 +297,7 @@ static PSI_mutex_info mrn_mutexes[] =
#endif #endif
/* global variables */ /* global variables */
bool mrn_initialized = false;
handlerton *mrn_hton_ptr; handlerton *mrn_hton_ptr;
HASH mrn_open_tables; HASH mrn_open_tables;
mysql_mutex_t mrn_open_tables_mutex; mysql_mutex_t mrn_open_tables_mutex;
...@@ -1957,6 +1959,8 @@ static int mrn_init(void *p) ...@@ -1957,6 +1959,8 @@ static int mrn_init(void *p)
mrn::PathMapper::default_mysql_data_home_path = mysql_data_home; mrn::PathMapper::default_mysql_data_home_path = mysql_data_home;
#endif #endif
mrn_initialized = true;
return 0; return 0;
error_allocated_long_term_share_hash_init: error_allocated_long_term_share_hash_init:
...@@ -2051,6 +2055,8 @@ static int mrn_deinit(void *p) ...@@ -2051,6 +2055,8 @@ static int mrn_deinit(void *p)
mysql_mutex_destroy(&mrn_query_log_mutex); mysql_mutex_destroy(&mrn_query_log_mutex);
mysql_mutex_destroy(&mrn_log_mutex); mysql_mutex_destroy(&mrn_log_mutex);
mrn_initialized = false;
return 0; return 0;
} }
......
/*
Copyright (C) 2024 Sutou Kouhei <kou@clear-code.com>
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
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern bool mrn_initialized;
#ifdef __cplusplus
}
#endif
sources = \ sources = \
mrn.hpp \
mrn_macro.hpp \ mrn_macro.hpp \
mrn_constants.hpp \ mrn_constants.hpp \
ha_mroonga.cpp \ ha_mroonga.cpp \
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_path_mapper.hpp> #include <mrn_path_mapper.hpp>
...@@ -51,6 +52,15 @@ MRN_API my_bool mroonga_command_init(UDF_INIT *init, UDF_ARGS *args, ...@@ -51,6 +52,15 @@ MRN_API my_bool mroonga_command_init(UDF_INIT *init, UDF_ARGS *args,
CommandInfo *info = NULL; CommandInfo *info = NULL;
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_command(): Mroonga isn't initialized");
goto error;
}
if (args->arg_count == 0) { if (args->arg_count == 0) {
grn_snprintf(message, grn_snprintf(message,
MYSQL_ERRMSG_SIZE, MYSQL_ERRMSG_SIZE,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_path_mapper.hpp> #include <mrn_path_mapper.hpp>
...@@ -44,6 +45,15 @@ MRN_API my_bool mroonga_escape_init(UDF_INIT *init, UDF_ARGS *args, ...@@ -44,6 +45,15 @@ MRN_API my_bool mroonga_escape_init(UDF_INIT *init, UDF_ARGS *args,
bool script_mode = false; bool script_mode = false;
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_escape(): Mroonga isn't initialized");
goto error;
}
if (!(1 <= args->arg_count && args->arg_count <= 2)) { if (!(1 <= args->arg_count && args->arg_count <= 2)) {
snprintf(message, snprintf(message,
MYSQL_ERRMSG_SIZE, MYSQL_ERRMSG_SIZE,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_err.h> #include <mrn_err.h>
...@@ -211,6 +212,14 @@ MRN_API my_bool mroonga_highlight_html_init(UDF_INIT *init, ...@@ -211,6 +212,14 @@ MRN_API my_bool mroonga_highlight_html_init(UDF_INIT *init,
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_highlight_html(): Mroonga isn't initialized");
goto error;
}
if (args->arg_count < 1) { if (args->arg_count < 1) {
snprintf(message, MYSQL_ERRMSG_SIZE, snprintf(message, MYSQL_ERRMSG_SIZE,
"mroonga_highlight_html(): wrong number of arguments: %u for 1+", "mroonga_highlight_html(): wrong number of arguments: %u for 1+",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_windows.hpp> #include <mrn_windows.hpp>
#include <mrn_table.hpp> #include <mrn_table.hpp>
...@@ -29,6 +30,13 @@ MRN_BEGIN_DECLS ...@@ -29,6 +30,13 @@ MRN_BEGIN_DECLS
MRN_API my_bool last_insert_grn_id_init(UDF_INIT *init, UDF_ARGS *args, char *message) MRN_API my_bool last_insert_grn_id_init(UDF_INIT *init, UDF_ARGS *args, char *message)
{ {
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"last_insert_grn_id(): Mroonga isn't initialized");
return 1;
}
if (args->arg_count != 0) { if (args->arg_count != 0) {
strcpy(message, "last_insert_grn_id must not have arguments"); strcpy(message, "last_insert_grn_id must not have arguments");
return 1; return 1;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_encoding.hpp> #include <mrn_encoding.hpp>
...@@ -53,6 +54,15 @@ MRN_API my_bool mroonga_normalize_init(UDF_INIT *init, UDF_ARGS *args, ...@@ -53,6 +54,15 @@ MRN_API my_bool mroonga_normalize_init(UDF_INIT *init, UDF_ARGS *args,
String *result_str = NULL; String *result_str = NULL;
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_normalize(): Mroonga isn't initialized");
goto error;
}
if (!(1 <= args->arg_count && args->arg_count <= 2)) { if (!(1 <= args->arg_count && args->arg_count <= 2)) {
sprintf(message, sprintf(message,
"mroonga_normalize(): Incorrect number of arguments: %u for 1..2", "mroonga_normalize(): Incorrect number of arguments: %u for 1..2",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_path_mapper.hpp> #include <mrn_path_mapper.hpp>
...@@ -74,6 +75,15 @@ MRN_API my_bool mroonga_query_expand_init(UDF_INIT *init, ...@@ -74,6 +75,15 @@ MRN_API my_bool mroonga_query_expand_init(UDF_INIT *init,
MRN_DBUG_ENTER_FUNCTION(); MRN_DBUG_ENTER_FUNCTION();
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_query_expand(): Mroonga isn't initialized");
goto error;
}
if (args->arg_count != 4) { if (args->arg_count != 4) {
sprintf(message, sprintf(message,
"mroonga_query_expand(): wrong number of arguments: %u for 4", "mroonga_query_expand(): wrong number of arguments: %u for 4",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_err.h> #include <mrn_err.h>
...@@ -135,6 +136,13 @@ MRN_API my_bool mroonga_snippet_init(UDF_INIT *init, UDF_ARGS *args, char *messa ...@@ -135,6 +136,13 @@ MRN_API my_bool mroonga_snippet_init(UDF_INIT *init, UDF_ARGS *args, char *messa
st_mrn_snip_info *snip_info = NULL; st_mrn_snip_info *snip_info = NULL;
bool can_open_snippet = TRUE; bool can_open_snippet = TRUE;
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_snippet(): Mroonga isn't initialized");
goto error;
}
if (args->arg_count < 11 || (args->arg_count - 11) % 3) if (args->arg_count < 11 || (args->arg_count - 11) % 3)
{ {
sprintf(message, "Incorrect number of arguments for mroonga_snippet(): %u", sprintf(message, "Incorrect number of arguments for mroonga_snippet(): %u",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/ */
#include <mrn.hpp>
#include <mrn_mysql.h> #include <mrn_mysql.h>
#include <mrn_mysql_compat.h> #include <mrn_mysql_compat.h>
#include <mrn_err.h> #include <mrn_err.h>
...@@ -194,6 +195,14 @@ MRN_API my_bool mroonga_snippet_html_init(UDF_INIT *init, ...@@ -194,6 +195,14 @@ MRN_API my_bool mroonga_snippet_html_init(UDF_INIT *init,
init->ptr = NULL; init->ptr = NULL;
if (!mrn_initialized)
{
snprintf(message,
MYSQL_ERRMSG_SIZE,
"mroonga_snippet_html(): Mroonga isn't initialized");
goto error;
}
if (args->arg_count < 1) { if (args->arg_count < 1) {
snprintf(message, MYSQL_ERRMSG_SIZE, snprintf(message, MYSQL_ERRMSG_SIZE,
"mroonga_snippet_html(): wrong number of arguments: %u for 1+", "mroonga_snippet_html(): wrong number of arguments: %u for 1+",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment