diff options
author | unknown <davi@endora.local> | 2007-11-01 17:29:20 -0200 |
---|---|---|
committer | unknown <davi@endora.local> | 2007-11-01 17:29:20 -0200 |
commit | 8f0df2efe85ae6d241ed045a4100d207ddb4ed1c (patch) | |
tree | e2439b0b42b30ea2e2147c6621485bbd2149cdb1 /sql/sql_connect.cc | |
parent | 17d2230550a34d3cd99d3eb34e9f4e07ca1872d8 (diff) | |
download | mariadb-git-8f0df2efe85ae6d241ed045a4100d207ddb4ed1c.tar.gz |
Bug#31850 Test crashes in "embedded" server
The mysql_change_user command fails to properly update the database pointer
when no database is selected, leading to "use after free" errors. The same
happens on the user privilege pointer in the thread security context.
The solution is to properly reset and update the database name. Also update
the user_priv pointer so that it doesn't point to freed memory.
sql/sql_connect.cc:
After a successful call to check_user() without specifying a new
database name, the previous database thd->db) is freed but the
pointer is not updated to NULL.
sql/sql_parse.cc:
Update the security_ctx->priv_user pointer as it is a alias for
the user security_ctx->user pointer. Also remove unneeded cast,
the x_free macro casts the argument.
Diffstat (limited to 'sql/sql_connect.cc')
-rw-r--r-- | sql/sql_connect.cc | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 8a817e5993a..adf0b9e01ed 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -316,17 +316,20 @@ int check_user(THD *thd, enum enum_server_command command, { DBUG_ENTER("check_user"); LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 }; - + + /* + Clear thd->db as it points to something, that will be freed when + connection is closed. We don't want to accidentally free a wrong + pointer if connect failed. Also in case of 'CHANGE USER' failure, + current database will be switched to 'no database selected'. + */ + thd->reset_db(NULL, 0); + #ifdef NO_EMBEDDED_ACCESS_CHECKS thd->main_security_ctx.master_access= GLOBAL_ACLS; // Full rights /* Change database if necessary */ if (db && db[0]) { - /* - thd->db is saved in caller and needs to be freed by caller if this - function returns 0 - */ - thd->reset_db(NULL, 0); if (mysql_change_db(thd, &db_str, FALSE)) { /* Send the error to the client */ @@ -358,14 +361,6 @@ int check_user(THD *thd, enum enum_server_command command, passwd_len != SCRAMBLE_LENGTH_323) DBUG_RETURN(ER_HANDSHAKE_ERROR); - /* - Clear thd->db as it points to something, that will be freed when - connection is closed. We don't want to accidentally free a wrong pointer - if connect failed. Also in case of 'CHANGE USER' failure, current - database will be switched to 'no database selected'. - */ - thd->reset_db(NULL, 0); - USER_RESOURCES ur; int res= acl_getroot(thd, &ur, passwd, passwd_len); #ifndef EMBEDDED_LIBRARY |