Skip to content

MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb#5291

Open
raghunandanbhat wants to merge 1 commit into
11.8from
11.8-mdev-40176
Open

MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb#5291
raghunandanbhat wants to merge 1 commit into
11.8from
11.8-mdev-40176

Conversation

@raghunandanbhat

@raghunandanbhat raghunandanbhat commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

fixes MDEV-40176

Problem:

When my_charpos_mb() is called with pos = end = NULL and the string has fewer than length characters, the end + 2 - start return expression evaluates end+2, forming the pointer NULL+2. Offsetting a null pointer is undefined behavior.

Fix:

Compute the integer difference before adding the offset. The result is identical but no invalid pointer is ever formed.

@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 modifies the pointer arithmetic in the my_charpos_mb function within strings/ctype-mb.c to calculate (end-start)+2 instead of end+2-start, preventing potential undefined behavior from performing pointer arithmetic out of bounds. There are no review comments, and 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.

…rpos_mb`

Problem:
  When `my_charpos_mb()` is called with pos = end = NULL and the string
  has fewer than `length` characters, the `end + 2 - start` return
  expression evaluates `end+2`, forming the pointer NULL+2. Offsetting
  a null pointer is undefined behavior.

Fix:
  Compute the integer difference before adding the offset. The result is
  identical but no invalid pointer is ever formed.
@raghunandanbhat raghunandanbhat changed the title MDEV-40176: UBSAN: runtime error: applying non-zero offset at strings/ctype-mb.c:261 MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb Jun 29, 2026
@raghunandanbhat raghunandanbhat marked this pull request as ready for review June 29, 2026 14:45
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.

1 participant