[MDEV-33158] The macro MYSQL_THDVAR_ULONG leads to undefined behaviour, calling mysql_sys_var_long Created: 2024-01-03  Updated: 2024-01-03

Status: Confirmed
Project: MariaDB Server
Component/s: Embedded Server, Server
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2, 11.3

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: UBSAN

Issue Links:
Blocks
is blocked by MDEV-26272 The macro MASTER_INFO_VAR invokes und... Closed
Relates
relates to MDEV-25454 Make MariaDB server UBSAN safe Confirmed

 Description   

Now that MDEV-26272 has been fixed and a cmake -DWITH_UBSAN=ON build with clang can pass the server bootstrap, we can find more undefined behaviour that is not flagged by GCC. Here is an example:

10.4 832e96deb6f368591dcb35a4fa33b2fd770aa17a

/mariadb/10.4/storage/innobase/handler/ha_innodb.cc:1821:9: runtime error: call to function mysql_sys_var_long(THD*, int) through pointer to incorrect function type 'unsigned long *(*)(THD *, int)'

This is flagged for the function thd_lock_wait_timeout(), which simply accesses a data member that has been defined as follows:

static MYSQL_THDVAR_ULONG(lock_wait_timeout, PLUGIN_VAR_RQCMDARG,
  "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back. Values above 100000000 disable the timeout.",
  NULL, NULL, 50, 0, 1024 * 1024 * 1024, 0);
// ...
static struct st_mysql_sys_var* innobase_system_variables[]= {
// ...
  MYSQL_SYSVAR(lock_wait_timeout),
// ...
  NULL
};
maria_declare_plugin(innobase)
{
// ...
innobase_system_variables
// ...
},
// ...
maria_declare_plugin_end;



 Comments   
Comment by Marko Mäkelä [ 2024-01-03 ]

A similar problem affects MYSQL_THDVAR_ULONGLONG and mysql_sys_var_longlong.

Generated at Thu Feb 08 10:36:49 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.