summaryrefslogtreecommitdiff
path: root/sql/set_var.h
diff options
context:
space:
mode:
authorkonstantin@mysql.com <>2006-04-07 23:37:06 +0400
committerkonstantin@mysql.com <>2006-04-07 23:37:06 +0400
commit518993312cb8f28ba8395e7ca140801c1fb96eca (patch)
tree8f4f2952727fffa7429bb8deb43a9a72dc7bf4e0 /sql/set_var.h
parent3c93e6efa5e53df71ad4fb0e1083ca0def251740 (diff)
downloadmariadb-git-518993312cb8f28ba8395e7ca140801c1fb96eca.tar.gz
A fix and a test case for Bug#16365 "Prepared Statements: DoS with
too many open statements". The patch adds a new global variable @@max_prepared_stmt_count. This variable limits the total number of prepared statements in the server. The default value of @@max_prepared_stmt_count is 16382. 16382 small statements (a select against 3 tables with GROUP, ORDER and LIMIT) consume 100MB of RAM. Once this limit has been reached, the server will refuse to prepare a new statement and return ER_UNKNOWN_ERROR (unfortunately, we can't add new errors to 4.1 without breaking 5.0). The limit is changeable after startup and can accept any value from 0 to 1 million. In case the new value of the limit is less than the current statement count, no new statements can be added, while the old still can be used. Additionally, the current count of prepared statements is now available through a global read-only variable @@prepared_stmt_count.
Diffstat (limited to 'sql/set_var.h')
-rw-r--r--sql/set_var.h59
1 files changed, 41 insertions, 18 deletions
diff --git a/sql/set_var.h b/sql/set_var.h
index 2ac4fc2c260..c6319a79cf6 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -47,13 +47,7 @@ public:
#if MYSQL_VERSION_ID < 50000
bool no_support_one_shot;
#endif
- sys_var(const char *name_arg)
- :name(name_arg), after_update(0)
-#if MYSQL_VERSION_ID < 50000
- , no_support_one_shot(1)
-#endif
- {}
- sys_var(const char *name_arg,sys_after_update_func func)
+ sys_var(const char *name_arg, sys_after_update_func func= NULL)
:name(name_arg), after_update(func)
#if MYSQL_VERSION_ID < 50000
, no_support_one_shot(1)
@@ -79,15 +73,35 @@ public:
};
-class sys_var_long_ptr :public sys_var
+/*
+ A base class for all variables that require its access to
+ be guarded with a mutex.
+*/
+
+class sys_var_global: public sys_var
+{
+protected:
+ pthread_mutex_t *guard;
+public:
+ sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
+ pthread_mutex_t *guard_arg)
+ :sys_var(name_arg, after_update_arg), guard(guard_arg) {}
+};
+
+
+/*
+ A global-only ulong variable that requires its access to be
+ protected with a mutex.
+*/
+
+class sys_var_long_ptr_global: public sys_var_global
{
public:
ulong *value;
- sys_var_long_ptr(const char *name_arg, ulong *value_ptr)
- :sys_var(name_arg),value(value_ptr) {}
- sys_var_long_ptr(const char *name_arg, ulong *value_ptr,
- sys_after_update_func func)
- :sys_var(name_arg,func), value(value_ptr) {}
+ sys_var_long_ptr_global(const char *name_arg, ulong *value_ptr,
+ pthread_mutex_t *guard_arg,
+ sys_after_update_func after_update_arg= NULL)
+ :sys_var_global(name_arg, after_update_arg, guard_arg), value(value_ptr) {}
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
@@ -97,6 +111,18 @@ public:
};
+/*
+ A global ulong variable that is protected by LOCK_global_system_variables
+*/
+
+class sys_var_long_ptr :public sys_var_long_ptr_global
+{
+public:
+ sys_var_long_ptr(const char *name_arg, ulong *value_ptr,
+ sys_after_update_func after_update_arg= NULL);
+};
+
+
class sys_var_ulonglong_ptr :public sys_var
{
public:
@@ -175,7 +201,7 @@ class sys_var_const_str :public sys_var
public:
char *value; // Pointer to const value
sys_var_const_str(const char *name_arg, const char *value_arg)
- :sys_var(name_arg), value((char*) value_arg)
+ :sys_var(name_arg),value((char*) value_arg)
{}
bool check(THD *thd, set_var *var)
{
@@ -221,10 +247,7 @@ public:
class sys_var_thd :public sys_var
{
public:
- sys_var_thd(const char *name_arg)
- :sys_var(name_arg)
- {}
- sys_var_thd(const char *name_arg, sys_after_update_func func)
+ sys_var_thd(const char *name_arg, sys_after_update_func func= NULL)
:sys_var(name_arg,func)
{}
bool check_type(enum_var_type type) { return 0; }