Skip to content

fix(linux-safe-mode): run MySQL executable comments and read them as each server does - #3790

Merged
datlechin merged 2 commits into
mainfrom
fix/linux-mysql-executable-comments
Oct 22, 2026
Merged

datlechin merged 2 commits into
mainfrom
fix/linux-mysql-executable-comments

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • MySQL and MariaDB executable comments (/*!, /*!NNNNN, /*M!) are code to the script lexer, up to the first */ outside a string, a quoted name or a line comment, as the server reads them.
  • The editor sends them as the mysql client does: each /*!40101 ... */; line of a dump is a statement of its own, a /*!50100 PARTITION BY ... */ stays with its CREATE TABLE, and a dumped trigger under DELIMITER ;; is one statement.
  • Safe Mode, the MySQL export guard, history and the catalog refresh read the text every way the client or a server may, and the strictest reading stands:
    • MySQL up to 8.0, MySQL 8.1 and later, MariaDB and a Galera node, at version 0 and at each version the text names. A comment a version skips ends at the first */ past one nested /* */. MySQL reads /*M! as a plain comment, MariaDB skips /*!50700 to /*!99999, Galera runs /*!99997.
    • MySQL 8.1 $tag$ quotes, so CREATE PROCEDURE p() LANGUAGE JAVASCRIPT AS $$ /* $$; DROP TABLE t; -- */ is destructive.
    • A DELIMITER line as SQL, since the server never reads it as a directive.
    • Backslash escapes on and off, " as a name (ANSI_QUOTES), and [name] as a name (MariaDB's MSSQL mode).
    • Whole, and as each piece a DELIMITER line cuts it into, since the driver splits an editor statement again.
  • Only readings that lex the text differently are tried, and the first destructive one ends the check. Text that names more than 16 versions, or whose readings would lex more than 32 MiB, counts as destructive. The scan for where each statement ends is linear instead of quadratic.
  • A /*! comment no longer makes a statement a write by itself: SELECT /*!40001 SQL_NO_CACHE */ * FROM t reads again under Read-Only and in an export.
  • History reads those readings too, so a credential statement that one of them exposes is withheld. A run over the history's 1 MiB limit is no longer read for credentials, since the store refuses it.
  • Completion reads the inside of a /*! comment as code, and Format SQL leaves a statement as typed when formatting would change the text of one.
  • Test changed on purpose: statement_access::tests::a_mysql_conditional_comment_is_read_as_code now expects SELECT 1 /*M!100000 , 2 */ to read.
  • The macOS classifier has a related gap: macOS: Safe Mode misreads version-gated and lowercase MySQL executable comments #3784.

Test plan

  • Fail on main: statement_access::tests::an_executable_comment_ends_where_the_server_ends_it and a_skipped_executable_comment_ends_where_the_server_ends_it (Write instead of Destructive).
  • New unit tests: server_reading (version digits per server, Galera), the dollar quote, DELIMITER line, sql_mode quoting and Galera cases in statement_access, a_credential_any_server_reading_runs_is_withheld, the script_corpus MySQL cases, safe_mode_gate::a_mysql_executable_comment_is_sent_and_read_as_the_server_reads_it, catalog_change::ddl_only_some_mysql_server_versions_run_counts, completion_scope::a_mysql_executable_comment_is_code and significant_tokens::a_mysql_executable_comment_must_stay_as_written.
  • Docker: flavour_suite::a_dump_runs_its_executable_comments runs a dump split as the editor splits it on MySQL 8.0 and MariaDB 10.11.
  • Every server rule above was measured on MySQL 8.0.46 and 8.4.11, MariaDB 10.11.19 and 11.4.13, and a Galera node.

Fixes #3783

@datlechin
datlechin enabled auto-merge (squash) October 22, 2026 14:32
@datlechin
datlechin merged commit f68dfb1 into main Oct 22, 2026
30 checks passed
@datlechin
datlechin deleted the fix/linux-mysql-executable-comments branch October 22, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: Safe Mode misreads MySQL executable comments, and the editor drops them

1 participant