-
unknown authored
There actually were several problems here: - WRITE-lock is required to load events from the mysql.event table, but in the read-only mode an ordinary user can not acquire it; - Security_context::master_access attribute was not properly initialized in Security_context::init(), which led to differences in behavior with and without debug configure options. - if the server failed to load events from mysql.event, it forgot to close the mysql.event table, that led to the coredump, described in the bug report. The patch is to fix all these problems: - Use the super-user to acquire WRITE-lock on the mysql.even table; - The WRITE-lock is acquired by the event scheduler in two cases: - on initial loading of events from the database; - when an event has been executed, so its attributes should be updated. Other cases when WRITE-lock is needed for the mysql.event table happen under the user account. So, nothing should be changed there for the read-only mode. The user is able to create/update/drop an event only if he is a super-user. - Initialize Security_context::master_access; - Close the mysql.event table in case something went wrong. mysql-test/r/events_bugs.result: Update result file. mysql-test/t/events_bugs.test: A test case for BUG#31111: --read-only crashes MySQL (events fail to load). sql/event_data_objects.cc: When the worker thread is going to drop event after the execution we should do it under the super-user privileges in order to be able to lock the mysql.event table for writing in the read-only mode. This is a system operation, where user SQL can not be executed. So, there is no risk in compromising security by dropping an event under the super-user privileges. sql/event_db_repository.cc: 1. Close tables if something went wrong in simple_open_n_lock_tables(); 2. As soon as the system event scheduler thread is running under the super-user privileges, we should always be able to acquire WRITE-lock on the mysql.event table. However, let's have an assert to check this. sql/event_scheduler.cc: Run the system event scheduler thread under the super-user privileges. In particular, this is needed to be able to lock the mysql.event table for writing when the server is running in the read-only mode. The event scheduler executes only system operations and does not execute user SQL (this is what the worker threads for). So, there is no risk in compromising security by running the event scheduler under the super-user privileges. sql/events.cc: Open the mysql.event table as the super user to be able to acquire WRITE-lock in the read-only mode. sql/sql_class.cc: Initialize Security_context::master_acces.
b6e4b103