summaryrefslogtreecommitdiff
path: root/sql/sql_db.cc
diff options
context:
space:
mode:
authorPraveenkumar Hulakund <praveenkumar.hulakund@oracle.com>2013-08-21 10:39:40 +0530
committerPraveenkumar Hulakund <praveenkumar.hulakund@oracle.com>2013-08-21 10:39:40 +0530
commit10a6aa256e965874b3a307f7d81393078a991544 (patch)
tree6c403dc88c8ca5b75a5384ae957f26dc42b865f8 /sql/sql_db.cc
parent55129f676accff001fcd7b60b049cdd0932442e8 (diff)
downloadmariadb-git-10a6aa256e965874b3a307f7d81393078a991544.tar.gz
Bug#11765252 - READ OF FREED MEMORY WHEN "USE DB" AND
"SHOW PROCESSLIST" Analysis: ---------- The problem here is, if one connection changes its default db and at the same time another connection executes "SHOW PROCESSLIST", when it wants to read db of the another connection then there is a chance of accessing the invalid memory. The db name stored in THD is not guarded while changing user DB and while reading the user DB in "SHOW PROCESSLIST". So, if THD.db is freed by thd "owner" thread and if another thread executing "SHOW PROCESSLIST" statement tries to read and copy THD.db at the same time then we may endup in the issue reported here. Fix: ---------- Used mutex "LOCK_thd_data" to guard THD.db while freeing it and while copying it to processlist.
Diffstat (limited to 'sql/sql_db.cc')
-rw-r--r--sql/sql_db.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index d3178fa0b99..4ddfad7206e 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1469,10 +1469,12 @@ static void mysql_change_db_impl(THD *thd,
we just call THD::reset_db(). Since THD::reset_db() does not releases
the previous database name, we should do it explicitly.
*/
-
- x_free(thd->db);
-
+ pthread_mutex_lock(&thd->LOCK_thd_data);
+ if (thd->db)
+ x_free(thd->db);
+ DEBUG_SYNC(thd, "after_freeing_thd_db");
thd->reset_db(new_db_name->str, new_db_name->length);
+ pthread_mutex_unlock(&thd->LOCK_thd_data);
}
/* 2. Update security context. */