MDEV-30297 Server crash / assertion failure in Compare_identifiers::operator upon dropping period with empty name#5235
MDEV-30297 Server crash / assertion failure in Compare_identifiers::operator upon dropping period with empty name#5235pranavktiwari wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the streq method in sql/vers_string.h to safely handle null pointers during string comparisons. The reviewer suggested optimizing this logic by checking for length mismatches first to fail fast, skipping the comparison call when the length is zero, and simplifying the null pointer checks.
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.
| if (str == NULL || b.str == NULL) | ||
| return str == b.str && length == b.length; | ||
|
|
||
| return length == b.length && | ||
| 0 == Compare()(*this, b); |
There was a problem hiding this comment.
We can optimize this comparison by failing fast when the lengths do not match, which is the most common case for non-equal strings. Additionally, we can avoid calling Compare() entirely when the length is 0 (since two empty strings are always equal under any collation). This also simplifies the NULL pointer handling.
if (length != b.length)
return false;
if (str == NULL || b.str == NULL)
return str == b.str;
return length == 0 || 0 == Compare()(*this, b);…perator upon dropping period with empty name Lex_cstring::streq() could invoke Compare_identifiers on default-constructed Lex_cstring objects (str == NULL, length == 0). Compare_identifiers assumes non-null strings and asserts in debug builds or crashes in non-debug builds. Guard against null string pointers in streq() before invoking the comparator.
f96c56c to
3ac0b2a
Compare
sanja-byelkin
left a comment
There was a problem hiding this comment.
why it is for 11.4 not for 10.11?
| alter table t drop period if exists for ``; | ||
| Warnings: | ||
| Note 1091 Can't DROP PERIOD ``; check that it exists | ||
| drop table t; |
fixes MDEV-30297
Problem:
`ALTER TABLE ... DROP PERIOD IF EXISTS FOR ``` can trigger an assertion failure in debug builds and crash in non-debug builds.
Cause:
Lex_cstring::streq() may invoke Compare_identifiers on default-constructed Lex_cstring objects (str == NULL, length == 0). Compare_identifiers assumes non-null string pointers and asserts or crashes when called with a null pointer.
Fix:
Add null-pointer handling to Lex_cstring::streq() and avoid calling Compare_identifiers when either string pointer is null. This prevents invalid comparisons while preserving existing behavior for initialized strings.