Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-free when pg_hint_plan.parse_messages is ERROR #142

Closed
wants to merge 1 commit into from

Conversation

Anisimov-ds
Copy link
Contributor

@Anisimov-ds Anisimov-ds commented Jun 26, 2023

This pull request resolves issue #141

PG_TRY();
{
/* Apply Set hints, then save it as the initial state */
setup_guc_enforcement(current_hint_state->set_hints,
Copy link
Collaborator

@michaelpq michaelpq Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. setup_guc_enforcement() itself has a stack manipulation, and set_config_option_noerror() is written to not throw an error, still we are doing so here. I am not sure what's the best solution is here, but this change makes the stack manipulation more complicated than it ought to be, IMO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that the patch is incorrect. Actually, any ERROR happening between the point where we have push_hint() up to the point where we enter in the TRY/CATCH block would cause an incorrect stack, and there can be much more that could trigger a corrupted stack. Just to mention one: out-of-memory failures. For instance, if a palloc() fails between the push_hint() and the TRY/CATCH block, we're out. I think that we should enlarge the window where we use the TRY/CATCH block instead, beginning it just after the hints are pushed on the stack.

@michaelpq michaelpq closed this Jun 29, 2023
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.

2 participants