Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6572

"USE dbname" with a bad sequence erroneously connects to a wrong database

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 5.3.12, 5.5.39, 10.0.14
    • 10.1.4
    • Character Sets
    • None

    Description

      I create a database with some question marks in the name:

      DROP DATABASE IF EXISTS `test????`;
      CREATE DATABASE `test????`;

      Now I run a "USE" query with a bad byte sequence:

      SET NAMES utf8;
      USE `test��`;
      SELECT DATABASE(), HEX(DATABASE());

      (notice. '��' is a four-byte UTF-8 character, which is considered as a wrong
      byte sequence by MariaDB's 3-byte "utf8").

      It erroneously connects to the database 'test????':

      ariaDB [(none)]> SET NAMES utf8;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [(none)]> USE `test��`;
      Database changed
      MariaDB [test��]> SELECT DATABASE(), HEX(DATABASE());
      +------------+------------------+
      | DATABASE() | HEX(DATABASE())  |
      +------------+------------------+
      | test????   | 746573743F3F3F3F |
      +------------+------------------+
      1 row in set (0.00 sec)

      The correct behaviour would be report either "unknown database",
      or "bad database name" or "Invalid utf8 character string: 'test\xF0\x9F\x98\x81'".

      The latter would be consistent with what's reported on attempt to
      create a database with such a broken name:

      MariaDB [test]> CREATE DATABASE `test��`;
      ERROR 1300 (HY000): Invalid utf8 character string: 'test\xF0\x9F\x98\x81'

      A similar problem also happens with table names.
      I create a table with question marks in its name:

      SET NAMES utf8;
      DROP TABLE IF EXISTS `test????`;
      CREATE TABLE `test????` (a INT);
      INSERT INTO `test????` values (10);

      Now I change the connection character set to utf8mb4 and run a SELECT query:

      SET NAMES utf8mb4;
      SELECT * FROM `test��������`;

      It returns rows from the table `test????`:

      +------+
      | a    |
      +------+
      |   10 |
      +------+
      1 row in set (0.01 sec)

      The expected behaviour would be to return some error.

      Attachments

        Issue Links

          Activity

            There are no comments yet on this issue.

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.