[MDEV-26504] THD::copy_db_to() fails to return error if THD::db is null Created: 2021-08-30  Updated: 2021-08-30  Resolved: 2021-08-30

Status: Closed
Project: MariaDB Server
Component/s: Embedded Server
Affects Version/s: 10.2.17
Fix Version/s: 10.2.41

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: not-10.3, not-10.4, not-10.5, not-10.6, not-10.7, regression-10.2

Issue Links:
Problem/Incident
is caused by MDEV-16473 WITH statement throws 'no database se... Closed

 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.


Generated at Thu Feb 08 09:45:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.