Skip to content

MDEV-30297 Server crash / assertion failure in Compare_identifiers::operator upon dropping period with empty name#5235

Open
pranavktiwari wants to merge 1 commit into
11.4from
11.4-MDEV-30297
Open

MDEV-30297 Server crash / assertion failure in Compare_identifiers::operator upon dropping period with empty name#5235
pranavktiwari wants to merge 1 commit into
11.4from
11.4-MDEV-30297

Conversation

@pranavktiwari

@pranavktiwari pranavktiwari commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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.

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

Copy link
Copy Markdown

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 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.

Comment thread sql/vers_string.h Outdated
Comment on lines +66 to +70
if (str == NULL || b.str == NULL)
return str == b.str && length == b.length;

return length == b.length &&
0 == Compare()(*this, b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.
@pranavktiwari pranavktiwari changed the title Modified logic. MDEV-30297 Server crash / assertion failure in Compare_identifiers::operator upon dropping period with empty name Jun 16, 2026

@sanja-byelkin sanja-byelkin 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.

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;

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.

add version marker

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.

3 participants