summaryrefslogtreecommitdiff
path: root/sql/sql_acl.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2012-11-22 10:19:31 +0100
committerSergei Golubchik <sergii@pisem.net>2012-11-22 10:19:31 +0100
commita48a91d90f07798deebe514d9d827fb719da7294 (patch)
treec438c045be1f3d8167b3746aa3ac87f848902aeb /sql/sql_acl.cc
parent3a1fdc9e7fc65e29320b988f9a69c8acab168ff9 (diff)
parent13ba0dd286f3296bfbbd202fa76d47770734b472 (diff)
downloadmariadb-git-a48a91d90f07798deebe514d9d827fb719da7294.tar.gz
5.3->5.5 merge
Diffstat (limited to 'sql/sql_acl.cc')
-rw-r--r--sql/sql_acl.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 8f27c45247e..b8e7d891e05 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -1633,14 +1633,20 @@ ulong acl_get(const char *host, const char *ip,
acl_entry *entry;
DBUG_ENTER("acl_get");
- mysql_mutex_lock(&acl_cache->lock);
- end=strmov((tmp_db=strmov(strmov(key, ip ? ip : "")+1,user)+1),db);
+ tmp_db= strmov(strmov(key, ip ? ip : "") + 1, user) + 1;
+ end= strnmov(tmp_db, db, key + sizeof(key) - tmp_db);
+
+ if (end >= key + sizeof(key)) // db name was truncated
+ DBUG_RETURN(0); // no privileges for an invalid db name
+
if (lower_case_table_names)
{
my_casedn_str(files_charset_info, tmp_db);
db=tmp_db;
}
key_length= (size_t) (end-key);
+
+ mysql_mutex_lock(&acl_cache->lock);
if (!db_is_pattern && (entry=(acl_entry*) acl_cache->search((uchar*) key,
key_length)))
{
@@ -4954,11 +4960,17 @@ static bool check_grant_db_routine(THD *thd, const char *db, HASH *hash)
bool check_grant_db(THD *thd,const char *db)
{
Security_context *sctx= thd->security_ctx;
- char helping [SAFE_NAME_LEN + USERNAME_LENGTH+2];
+ char helping [SAFE_NAME_LEN + USERNAME_LENGTH+2], *end;
uint len;
bool error= TRUE;
- len= (uint) (strmov(strmov(helping, sctx->priv_user) + 1, db) - helping) + 1;
+ end= strmov(helping, sctx->priv_user) + 1;
+ end= strnmov(end, db, helping + sizeof(helping) - end);
+
+ if (end >= helping + sizeof(helping)) // db name was truncated
+ return 1; // no privileges for an invalid db name
+
+ len= (uint) (end - helping) + 1;
mysql_rwlock_rdlock(&LOCK_grant);