MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb#5291
Open
raghunandanbhat wants to merge 1 commit into
Open
MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb#5291raghunandanbhat wants to merge 1 commit into
my_charpos_mb#5291raghunandanbhat wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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.
ec64853 to
f696d8e
Compare
strings/ctype-mb.c:261my_charpos_mb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes MDEV-40176
Problem:
When
my_charpos_mb()is called with pos = end = NULL and the string has fewer thanlengthcharacters, theend + 2 - startreturn expression evaluatesend+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.