Skip to content

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

Merged
grooverdan merged 2 commits into
10.11from
11.8-mdev-40176
Jun 29, 2026
Merged

MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb#5291
grooverdan merged 2 commits into
10.11from
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.

@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
raghunandanbhat and others added 2 commits June 30, 2026 07:21
…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.
…rpos_mb` (2)

my_numchars_mb and my_charpos_mb both used their cs argument
so remove the notused attribute on them.
@CLAassistant

CLAassistant commented Jun 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@grooverdan grooverdan changed the base branch from 11.8 to 10.11 June 29, 2026 21:28
@grooverdan grooverdan enabled auto-merge (rebase) June 29, 2026 21:30
@grooverdan grooverdan merged commit f41aca2 into 10.11 Jun 29, 2026
16 of 17 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.

3 participants