[OSS-ONLY] Reset pg_strtok state after PLtsql node deserialization#4848
Draft
manisha-deshpande wants to merge 1 commit into
Draft
[OSS-ONLY] Reset pg_strtok state after PLtsql node deserialization#4848manisha-deshpande wants to merge 1 commit into
manisha-deshpande wants to merge 1 commit into
Conversation
Reset pg_strtok_ptr to NULL after pltsql_nodeRead() returns so the static tokenizer state isn't left pointing into a memory context that gets reset between statements. Task: BABEL-6037 Signed-off-by: Manisha Deshpande <mmdeshp@amazon.com>
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.
Description
This is a follow-up cleanup to the cross-session ANTLR parse tree caching feature added in #4547, which introduced an extension-side node serializer/deserializer (
pltsql_stringToNode) that uses the engine's tokenizer via the newpg_strtok_init()setter (added in the corresponding engine PR #733).Currently,
pltsql_stringToNode()callspg_strtok_init(str)on entry but does not reset the staticpg_strtok_ptrbefore returning. Because the input string lives in a per-statement memory context that gets reset between SQL commands, the tokenizer pointer is left pointing into freed memory until the next caller ofstringToNode()overwrites it. With this change,pltsql_stringToNode()resetspg_strtok_ptrto NULL before returning, matching PG's clean-state convention.Raised during code review of the engine-side
pg_strtok_init()addition. Behavior is unchanged in practice - the dangling pointer was never dereferenced because PG'sstringToNodeInternal()always overwrites it with its own input before any read (verified via gdb onpg_get_expr/pg_get_constraintdefpaths after a cached procedure EXEC). This is a defensive cleanup to remove the stale-pointer footgun for any future caller that might read the static directly.Issues Resolved
BABEL-6037
Test Scenarios Covered
EXECof a persistently cached procedure followed by apg_get_exprcall in the same backend; confirmedpg_strtok_ptris reset to0x0afterpltsql_stringToNodereturns instead of being left dangling, pointing to a wiped memory address.Boundary conditions -
N/A
Arbitrary inputs -
N/A
Negative test cases -
N/A
Minor version upgrade tests -
N/A
Major version upgrade tests -
N/A
Performance tests -
N/A
Tooling impact -
N/A
Client tests -
N/A
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.