diff options
author | Praveenkumar Hulakund <praveenkumar.hulakund@oracle.com> | 2013-08-21 10:39:40 +0530 |
---|---|---|
committer | Praveenkumar Hulakund <praveenkumar.hulakund@oracle.com> | 2013-08-21 10:39:40 +0530 |
commit | 3b1e98d21844b0f32f6e5fe9df447046eb471453 (patch) | |
tree | 6c403dc88c8ca5b75a5384ae957f26dc42b865f8 /sql/sql_class.h | |
parent | fb2a2d25625f54eab60ff902ab667efbd7891ee5 (diff) | |
download | mariadb-git-3b1e98d21844b0f32f6e5fe9df447046eb471453.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_class.h')
-rw-r--r-- | sql/sql_class.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h index 0942e9274b1..9a9b2058e2b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -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 @@ -2284,6 +2284,12 @@ public: */ bool set_db(const char *new_db, size_t new_db_len) { + /* + Acquiring mutex LOCK_thd_data as we either free the memory allocated + for the database and reallocate the memory for the new db or memcpy + the new_db to the db. + */ + pthread_mutex_lock(&LOCK_thd_data); /* Do not reallocate memory if current chunk is big enough. */ if (db && new_db && db_length >= new_db_len) memcpy(db, new_db, new_db_len+1); @@ -2293,6 +2299,7 @@ public: db= new_db ? my_strndup(new_db, new_db_len, MYF(MY_WME)) : NULL; } db_length= db ? new_db_len : 0; + pthread_mutex_unlock(&LOCK_thd_data); return new_db && !db; } |