Skip to content

MDEV-40006: Prepared Statement Crash in varchar_upper_cmp_transformer() for '?'#5370

Merged
bsrikanth-mariadb merged 1 commit into
11.4from
11.4-MDEV-40006-prepared-stmt-exec-crash-with-utf8mb4
Jul 11, 2026
Merged

MDEV-40006: Prepared Statement Crash in varchar_upper_cmp_transformer() for '?'#5370
bsrikanth-mariadb merged 1 commit into
11.4from
11.4-MDEV-40006-prepared-stmt-exec-crash-with-utf8mb4

Conversation

@bsrikanth-mariadb

@bsrikanth-mariadb bsrikanth-mariadb commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

MDEV-40006: Prepared Statement Crash in varchar_upper_cmp_transformer() for '?'

Item_func_in::varchar_upper_cmp_transformer() clones Item_func_in
and its arguments and doesn't check if cloning has succeed.

Item_param (PS parameter, '?') doesn't implement cloning so will return
NULL from clone(). This will cause a crash.

Fixed by making varchar_upper_cmp_transformer() check clone results for NULL.
(Adding cloning support to Item_param is out of scope of this patch).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a crash during prepared statement execution when the character set is set to utf8mb4 (MDEV-40006) by adding a null check for the cloned item cl returned by deep_copy_with_checks in sql/opt_rewrite_remove_casefold.cc before dereferencing it. It also adds a corresponding test case to verify the fix. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread mysql-test/main/prepare.result Outdated
# MDEV-40006: prepared statement execution crash when names is set to utf8mb4
#
set names utf8mb4;
CREATE TABLE t (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use the table t1 please

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And fix trailing whitespaces.

Comment thread sql/opt_rewrite_remove_casefold.cc Outdated
return this;
trace_upper_removal_rewrite(thd, this, res);
return res;
if (cl)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To minimize the patch I'd change this to

if (!cl)
 return this;

@spetrunia

Copy link
Copy Markdown
Member

suggested commit comment

MDEV-40006: Prepared Statement Crash in varchar_upper_cmp_transformer() for '?'

Item_func_in::varchar_upper_cmp_transformer() clones Item_func_in
and its arguments and doesn't check if cloning has succeed.

Item_param (PS parameter, '?') doesn't implement cloning so will return
NULL from clone(). This will cause a crash.

Fixed by making varchar_upper_cmp_transformer() check clone results for NULL.
(Adding cloning support to Item_param is out of scope of this patch).

@spetrunia spetrunia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok to push after all is addressed.

…() for '?'

Item_func_in::varchar_upper_cmp_transformer() clones Item_func_in
and its arguments and doesn't check if cloning has succeed.

Item_param (PS parameter, '?') doesn't implement cloning so will return
NULL from clone(). This will cause a crash.

Fixed by making varchar_upper_cmp_transformer() check clone results for NULL.
(Adding cloning support to Item_param is out of scope of this patch).
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 11.4-MDEV-40006-prepared-stmt-exec-crash-with-utf8mb4 branch from ef98ea3 to 40de612 Compare July 10, 2026 12:03
@bsrikanth-mariadb bsrikanth-mariadb changed the title MDEV-40006: prepared stmt execution crash when names is set to utf8m4 MDEV-40006: Prepared Statement Crash in varchar_upper_cmp_transformer() for '?' Jul 10, 2026
@bsrikanth-mariadb bsrikanth-mariadb merged commit 40de612 into 11.4 Jul 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants