summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2021-04-24 09:06:16 +0300
committerAleksey Midenkov <midenok@gmail.com>2021-04-27 09:08:44 +0300
commit23e090626a9138f44905a5a8e681e8952f98aac7 (patch)
tree68ec2e87bc31624dd6834bde7f22c6ba6ff3bdb1
parent6d73282b136058deb992fdb758d8992fa186e73e (diff)
downloadmariadb-git-23e090626a9138f44905a5a8e681e8952f98aac7.tar.gz
MDEV-20842 Crash using versioning plugin functions after plugin was removed from server
Remove plugin functions via item_create_remove() at deinit time.
-rw-r--r--mysql-test/suite/versioning/r/trx_id.result6
-rw-r--r--mysql-test/suite/versioning/t/trx_id.test8
-rw-r--r--plugin/versioning/versioning.cc1
-rw-r--r--sql/item_create.cc15
-rw-r--r--sql/item_create.h1
5 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/suite/versioning/r/trx_id.result b/mysql-test/suite/versioning/r/trx_id.result
index 58d02505fb6..ea06a2e545d 100644
--- a/mysql-test/suite/versioning/r/trx_id.result
+++ b/mysql-test/suite/versioning/r/trx_id.result
@@ -506,3 +506,9 @@ add period for system_time(`row_start`,`row_end`),
modify x int after row_start,
with system versioning;
create or replace database test;
+#
+# MDEV-20842 Crash using versioning plugin functions after plugin was removed from server
+#
+uninstall plugin test_versioning;
+select trt_begin_ts(0);
+ERROR 42000: FUNCTION trt_begin_ts does not exist
diff --git a/mysql-test/suite/versioning/t/trx_id.test b/mysql-test/suite/versioning/t/trx_id.test
index 7dfc8acb080..b68d5513dd9 100644
--- a/mysql-test/suite/versioning/t/trx_id.test
+++ b/mysql-test/suite/versioning/t/trx_id.test
@@ -529,5 +529,11 @@ alter table t add `row_start` bigint unsigned as row start,
modify x int after row_start,
with system versioning;
-
create or replace database test;
+
+--echo #
+--echo # MDEV-20842 Crash using versioning plugin functions after plugin was removed from server
+--echo #
+uninstall plugin test_versioning;
+--error ER_SP_DOES_NOT_EXIST
+select trt_begin_ts(0);
diff --git a/plugin/versioning/versioning.cc b/plugin/versioning/versioning.cc
index 7e3c29e1494..56f8f1f5a1d 100644
--- a/plugin/versioning/versioning.cc
+++ b/plugin/versioning/versioning.cc
@@ -175,6 +175,7 @@ static int versioning_plugin_init(void *p __attribute__ ((unused)))
static int versioning_plugin_deinit(void *p __attribute__ ((unused)))
{
DBUG_ENTER("versioning_plugin_deinit");
+ (void) item_create_remove(func_array);
DBUG_RETURN(0);
}
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 48e396210a5..70ac2abe959 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -7465,6 +7465,21 @@ int item_create_append(Native_func_registry array[])
DBUG_RETURN(0);
}
+int item_create_remove(Native_func_registry array[])
+{
+ Native_func_registry *func;
+
+ DBUG_ENTER("item_create_remove");
+
+ for (func= array; func->builder != NULL; func++)
+ {
+ if (my_hash_delete(& native_functions_hash, (uchar*) func))
+ DBUG_RETURN(1);
+ }
+
+ DBUG_RETURN(0);
+}
+
/*
Empty the hash table for native functions.
Note: this code is not thread safe, and is intended to be used at server
diff --git a/sql/item_create.h b/sql/item_create.h
index b9d5ab9f377..7e92016ab96 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -214,6 +214,7 @@ struct Native_func_registry
int item_create_init();
int item_create_append(Native_func_registry array[]);
+int item_create_remove(Native_func_registry array[]);
void item_create_cleanup();
Item *create_func_dyncol_create(THD *thd, List<DYNCALL_CREATE_DEF> &list);