Skip to content

PG-2014 Initalize nested query stack to fix crash on DDL#584

Merged
artemgavrilov merged 1 commit intopercona:release-2.3.1from
jeltz:nested-queries-crash
Nov 21, 2025
Merged

PG-2014 Initalize nested query stack to fix crash on DDL#584
artemgavrilov merged 1 commit intopercona:release-2.3.1from
jeltz:nested-queries-crash

Conversation

@jeltz
Copy link
Copy Markdown
Contributor

@jeltz jeltz commented Nov 20, 2025

The pgsm_ProcessUtility() which handles DDL increments nesting_level but does not put a query text on the next_queries stack while pgsm_ExecutorRun() does both. It is unclear to me if this is a mistake or by design but since readers of the query check for is the query text pointer is NULL and pgsm_ExecutorRun() reset the pointer to NULL before returning it is safe as long as we initialize the stack to all NULL pointers, which we did not.

This bug was found by our test suite in Jenkins on some RHEL based distro version and seems to mostly happen when the first query of a backend is CREATE EXTENSION and we have enabled query normalization but it is entirely possible that it could happen under other circumstances too.

The use of calloc() over palloc0() is to keep the patch small since the previous code used malloc().

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (b00caaf) to head (3a9975d).
⚠️ Report is 3 commits behind head on release-2.3.1.

Additional details and impacted files
@@                Coverage Diff                @@
##           release-2.3.1     #584      +/-   ##
=================================================
+ Coverage          85.46%   85.48%   +0.01%     
=================================================
  Files                  3        3              
  Lines               1342     1343       +1     
  Branches             215      215              
=================================================
+ Hits                1147     1148       +1     
  Misses                92       92              
  Partials             103      103              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeltz jeltz force-pushed the nested-queries-crash branch from 8ad7096 to ee5f374 Compare November 20, 2025 20:33
The pgsm_ProcessUtility() which handles DDL increments nesting_level but
does not put a query text on the next_queries stack while
pgsm_ExecutorRun() does both. It is unclear to me if this is a mistake
or by design but since readers of the query check for is the query text
pointer is NULL and pgsm_ExecutorRun() reset the pointer to NULL before
returning it is safe as long as we initialize the stack to all NULL
pointers, which we did not.

This bug was found by our test suite in Jenkins on some RHEL based
distro version and seems to mostly happen when the first query of a
backend is CREATE EXTENSION and we have enabled query normalization but
it is entirely possible that it could happen under other circumstances
too.

The use of calloc() over palloc0() is to keep the patch small since the
previous code used malloc().
@jeltz jeltz force-pushed the nested-queries-crash branch from ee5f374 to 3a9975d Compare November 20, 2025 20:37
@jeltz jeltz changed the title Zero-initalize nested query stack to fix crash on DDL PG-2014 Initalize nested query stack to fix crash on DDL Nov 20, 2025
@jeltz jeltz marked this pull request as ready for review November 20, 2025 20:37
@jeltz jeltz requested a review from artemgavrilov as a code owner November 20, 2025 20:37
@jeltz jeltz changed the base branch from main to release-2.3.1 November 21, 2025 09:24
@artemgavrilov artemgavrilov merged commit bcd345a into percona:release-2.3.1 Nov 21, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants