Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35554/ MDEV-33158 UBSAN runtime error: call to function show_cached_thread_count() (and plugin interface) #3737

Open
wants to merge 3 commits into
base: 10.5
Choose a base branch
from

Conversation

grooverdan
Copy link
Member

  • The Jira issue number for this PR is: MDEV-35554

Description

clang/UBSAN shows this up as an error as the argument is incorrect.

The argument is void* rather than char*.

Release Notes

not required.

How can this PR be tested?

basic bootstrap when compiled WITH_UBSAN under clang.

If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label Jan 9, 2025
@grooverdan grooverdan requested a review from bnestere January 9, 2025 06:36
through pointer to incorrect function type.

The argument is void* rather than char*.

This shows up with UBSAN testing under clang.
In plugins, use the correct resolver for ULONG and ULONGLONG
types.

InnoDB has a UINT type as evidenced by "Unknown variable type code 0x182
in plugin 'InnoDB'." so the implemntation for UNSIGNED INT was added.
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from 8116295 to 50ebc21 Compare January 9, 2025 07:18
@grooverdan grooverdan changed the title MDEV-35554 runtime error: call to function show_cached_thread_count() MDEV-35554/ MDEV-33158 UBSAN runtime error: call to function show_cached_thread_count() (and plugin interface) Jan 9, 2025
The mismatch occurs on the function calls as in the sql/sql_udf.h the
types of "error" and "is_null" are unsigned char rather than char.

This is corrected for the udf functions:
* spider_direct_sql
* spider_direct_bg_sql
* spider_flush_table_mon_cache
* spider_copy_tables
* spider_ping_table
@grooverdan grooverdan force-pushed the MDEV-35554-ubsan-show_cached_thread_count branch from 6dcbc88 to d85cd2a Compare January 10, 2025 04:21
@mariadb-YuchenPei
Copy link
Contributor

The spider commit (d85cd2a) lgtm, thanks for the fix

Copy link
Contributor

@bnestere bnestere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @grooverdan !

The first two commits look good, thanks! I left a couple minor notes to consider. Also, I am leaving the third commit for @mariadb-YuchenPei to review.

@@ -3227,6 +3227,11 @@ static int *mysql_sys_var_int(THD* thd, int offset)
return (int *) intern_sys_var_ptr(thd, offset, true);
}

static unsigned int *mysql_sys_var_uint(THD* thd, int offset)
{
return (unsigned int *) intern_sys_var_ptr(thd, offset, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of C-style casts in this area, though it's cpp code. Perhaps now would be a good time to refactor them to the proper casting style.

@@ -714,8 +714,8 @@ int spider_udf_bg_copy_exec_sql(
long long spider_copy_tables_body(
UDF_INIT *initid,
UDF_ARGS *args,
char *is_null,
char *error
unsigned char *is_null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the MDEV-35735 JIRA you mention

performed manual testing in UBSAN environment as its not completely runable in mtr:

I'd say that'd be good to mention in the commit message too (along with the test case, and also some more detail on why you couldn't use MTR)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although now after some of my own attempts to reproduce/test the issue (which I couldn't actually reproduce the error following the JIRA commands), I now see @mariadb-YuchenPei is assigned to review the spider changes, so I'll let him take over for this part.

case PLUGIN_VAR_BOOL:
((thdvar_bool_t *) opt)->resolve= mysql_sys_var_char;
break;
case PLUGIN_VAR_INT:
((thdvar_int_t *) opt)->resolve= mysql_sys_var_int;
break;
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
((thdvar_uint_t *) opt)->resolve= mysql_sys_var_uint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the second commit message (for MDEV-33158), it'd be good to re-mention the MTR tests that verify the fixes, as you do on JIRA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MariaDB Foundation Pull requests created by MariaDB Foundation
Development

Successfully merging this pull request may close these issues.

3 participants