⚡ Sangsakala Proxy 🏠 Home
Skip to content

fix: apply the MySQL comment rules to Dialect.MARIADB - #2891

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:mariadb-executable-comments
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:mariadb-executable-comments

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

SimpleCharStream.BeginToken applies the MySQL comment rules from #2728 (-- starts a comment only before whitespace or a control character, and /*! ... */ contents are parsed as SQL) only when the dialect is MYSQL. MariaDB's lexer works the same way and also runs its own /*M! ... */ comments, so under Dialect.MARIADB SQL that the server executes was thrown away as a comment:

  1. SELECT 1 /*M! UNION SELECT pw FROM secrets */, SELECT 1 /*! UNION SELECT pw FROM secrets */ and the /*!50000 ... */ form parse as SELECT 1 and TablesNamesFinder finds no table, while MariaDB 13.0.2 returns the rows of secrets.
  2. SELECT a FROM t WHERE a = 1--1 UNION SELECT pw FROM secrets parses as ... WHERE a = 1, while MariaDB reads a = 1 - -1 and runs the UNION.

So a table allowlist or a FeaturesAllowed check run with the MariaDB dialect looks at a different statement from the one the server runs.

The rules now apply to MARIADB too, with MariaDB's own version handling, which I checked against the server: /*M! and /*M!###### are executable, a sixth version digit always belongs to the version (MySQL only takes it before whitespace), and /*!50700 through /*!99999 are skipped while /*M! comments in that range are not. withMySqlServerVersion takes the MariaDB version there (130002 for 13.0.2), and a conditional comment without it still fails instead of being dropped. MYSQL and the other dialects are unchanged. preservesOtherDialectCommentsAndQuotedBodies expected MARIADB to discard /*!90702 +2 */, so it now leaves MARIADB out the way it leaves out MYSQL.

I ran 45 statements on MariaDB 13.0.2 (through mariadb --comments, so the client does not strip them) both as written and as rendered by JSqlParser, and the results match for all of them. The new MySqlCommentTest cases fail before the change and pass after; ./gradlew check and mvn verify pass.

The -- whitespace rule and executable comments were only lexed the
MySQL way under Dialect.MYSQL. MariaDB follows the same rules and also
runs /*M! ... */, so under MARIADB SQL the server executes was dropped
as a comment: SELECT 1 /*M! UNION SELECT pw FROM secrets */ parsed as
SELECT 1. The rules now apply to MARIADB as well, with MariaDB's own
version handling: a sixth digit always belongs to the version, and
/*!50700 through /*!99999 are skipped while /*M! ones are not.

This branch has not been deployed

No deployments
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.

1 participant