Repository navigation
Fix inverted SPI result checks that could crash the backend - #69
Merged
Merged
Conversation
After creating the "template" table, gtt_create_table_statement() and
gtt_create_table_as() look up the OID of the new relation by name with
SPI and then read SPI_tuptable->vals[0]. The result was validated with
if (result != SPI_OK_SELECT && SPI_processed != 1)
which only raises an error when *both* conditions are true. When the
SELECT succeeds but returns no row (for example when an event trigger
renames the freshly created table, or in any other case where the name
lookup misses), the check passes and vals[0] is read from an empty
result set. This dereferences an uninitialized pointer and crashes the
backend with a segmentation fault, which makes the postmaster restart
all the sessions of the cluster.
Use || so that any unexpected result is reported as a regular error.
Also fix the validity check of the temporary table OID in the WITH DATA
path of CREATE TABLE AS, which was testing gttOid (already validated)
instead of the value that was just fetched, gtt.temp_relid.
Add regression test 20_spi_lookup that forces the lookup to return no
row for both CREATE GLOBAL TEMPORARY TABLE and CREATE GLOBAL TEMPORARY
TABLE ... AS. Without the fix the backend crashes; with the fix both
statements fail cleanly and the session remains usable.
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.
After creating the "template" table, gtt_create_table_statement() and gtt_create_table_as() look up the OID of the new relation by name with SPI and then read SPI_tuptable->vals[0]. The result was validated with
which only raises an error when both conditions are true. When the SELECT succeeds but returns no row (for example when an event trigger renames the freshly created table, or in any other case where the name lookup misses), the check passes and vals[0] is read from an empty result set. This dereferences an uninitialized pointer and crashes the backend with a segmentation fault, which makes the postmaster restart all the sessions of the cluster.
Use || so that any unexpected result is reported as a regular error. Also fix the validity check of the temporary table OID in the WITH DATA path of CREATE TABLE AS, which was testing gttOid (already validated) instead of the value that was just fetched, gtt.temp_relid.
Add regression test 20_spi_lookup that forces the lookup to return no row for both CREATE GLOBAL TEMPORARY TABLE and CREATE GLOBAL TEMPORARY TABLE ... AS. Without the fix the backend crashes; with the fix both statements fail cleanly and the session remains usable.