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

THD::copy_db_to() fails to return error if THD::db is null

    XMLWordPrintable

    Details

      Description

      GCC 11.2.0 reported the following warning for CMAKE_BUILD_TYPE=RelWithDebInfo:

      10.2 fda704c82c982c554ca0f0d28cb08ca972c4ddd9

      /mariadb/10.2o/sql/table.h: In function 'bool dispatch_command(enum_server_command, THD*, char*, uint, bool, bool)':
      /mariadb/10.2o/sql/table.h:1915:14: warning: 'db.st_mysql_lex_string::length' may be used uninitialized in this function [-Wmaybe-uninitialized]
       1915 |     db_length= db_length_arg;
            |     ~~~~~~~~~^~~~~~~~~~~~~~~
      /mariadb/10.2o/sql/sql_parse.cc:1935:16: note: 'db.st_mysql_lex_string::length' was declared here
       1935 |     LEX_STRING db;
            |                ^~
      

      The reason for this is that THD::copy_db_to() may return false even when it is not assigning db:

          if (thd->copy_db_to(&db.str, &db.length))
            break;
      

      The following fixes that:

      diff --git a/sql/sql_class.h b/sql/sql_class.h
      index 50ab3c56ca9..5f871f9caf6 100644
      --- a/sql/sql_class.h
      +++ b/sql/sql_class.h
      @@ -4003,10 +4003,8 @@ class THD :public Statement,
               for any CTE references.
             */
             if (!lex->with_cte_resolution)
      -      {
               my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
      -        return TRUE;
      -      }
      +      return TRUE;
           }
           else
           {
      

      It is unclear whether this bug has any impact on 10.2, because the invocation that GCC 11 complained about is in the handling of COM_FIELD_LIST, which is almost dead code. As far as I can tell, that code is only used in the embedded server implementation of mysql_list_fields().

      In 10.3 and later, the function THD::copy_db_to() already returned true in this case.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marko Marko Mäkelä
              Reporter:
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration