Repository navigation
Conversation
Analysis:
The stack overrun check added by MDEV-33843 is executed only in
my_xpath_parse_OrExpr(). The XPath grammar rule
UnaryExpr ::= '-' UnaryExpr
recurses directly in my_xpath_parse_UnaryExpr(), so a path made of many
'-' tokens consumes one stack frame per token without any limit and
overruns the thread stack. UPDATEXML() and EXTRACTVALUE() parse the path
in fix_fields(), therefore any user who can run a SELECT can terminate
the server with
SELECT UPDATEXML(NULL, REPEAT('-', 100000), 1);
Before this patch the statement makes the backend exit with SIGSEGV
(exit status 139) and the client reports "Lost connection to server
during query". The equivalent parenthesized expression is already
rejected with ER_STACK_OVERRUN_NEED_MORE because it re-enters
my_xpath_parse_OrExpr().
Fix:
Run check_stack_overrun() at the entry of my_xpath_parse_UnaryExpr(),
as my_xpath_parse_OrExpr() does, and add a regression case to
mysql-test/main/xml that expects ER_STACK_OVERRUN_NEED_MORE.
The same statement then returns the regular stack-overrun error and the
server stays alive. main.xml passes.
gkodinov
approved these changes
Nov 2, 2026
gkodinov
left a comment
Member
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
LGTM! A very good analysis!
I'd say let's please file a separate jira: it's a different code path. But I'll leave this to the final reviewer to decide.
Please stay tuned for the final review.
Member
|
and please rebase it onto 10.11, that's where the first fix was |
mariadb-RuchaDeodhar
approved these changes
Nov 2, 2026
Contributor
|
looks ok. thank you! |
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.
Problem
MDEV-33843 added a
check_stack_overrun()guard tomy_xpath_parse_OrExpr(), but the XPath ruleUnaryExpr ::= '-' UnaryExprrecurses directly inmy_xpath_parse_UnaryExpr(). A path argument made of many consecutive-tokens therefore bypasses the guard and exhausts the backend thread stack.Reproducer
Before the patch the backend crashes (SIGSEGV, exit 139) and the client reports
ERROR 2013 (HY000): Lost connection to server during query.REPEAT('(', 100000)is already handled correctly, which shows the missing guard is specific to the unary-minus recursion.Fix
Add the same
check_stack_overrun(xpath->thd, STACK_MIN_SIZE, NULL)check at the entry ofmy_xpath_parse_UnaryExpr(), so every recursive call is bounded.After the patch the statement returns the controlled
ER_STACK_OVERRUN_NEED_MOREerror andmariadbdkeeps running.Tests
New case in
mysql-test/main/xml.test;main.xmlpasses. Without the patch the same test kills the server, so it fails without the fix.This is a follow-up to MDEV-33843 (commit 7811201). Happy to file a separate MDEV if preferred.