pgsql: Fix potential crash after constraint violation errors in partiti

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix potential crash after constraint violation errors in partiti
Date: 2020-03-23 22:04:03
Message-ID: E1jGVAx-00021j-D2@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix potential crash after constraint violation errors in partitioned tables.

During the reporting of constraint violations for partitioned tables,
ExecPartitionCheckEmitError(), ExecConstraints(),
ExecWithCheckOptions() set the slot descriptor of the input slot to
the root partition's tuple desc. That's generally problematic when
the slot could be used by other routines, but can cause crashes after
the introduction of slots with "fixed" tuple descriptors in
ad7dbee368a.

The problem likely escaped detection so far for two reasons: First,
currently the only known way that these routines are used with a
partitioned table that is not "owned" by partitioning code is when
"fast defaults" are used for the child partition. Second, as an error
is raised afterwards, an "external" slot that had its descriptor
changed, is very unlikely to continue being used.

Even though the issue currently is only known to cause a crash for
11 (as that has both fast defaults and "fixed" slot descriptors), it
seems worth applying the fix to 10 too. Potentially changing random
slots is hazardous.

Regression tests will be added in a separate commit, as it seems best
to add them for master and 12 too.

Reported-By: Daniel WM
Author: Andres Freund
Bug: #16293
Discussion: https://postgr.es/m/16293-26f5777d10143a66@postgresql.org
Backpatch: 11, 10 only

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/44170a58092d74913779181392015c9994a2dfc3

Modified Files
--------------
src/backend/executor/execMain.c | 8 ++++++++
1 file changed, 8 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2020-03-23 22:06:34 pgsql: Add regression tests for constraint errors in partitioned tables
Previous Message Andres Freund 2020-03-23 22:04:00 pgsql: Fix potential crash after constraint violation errors in partiti