Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac8d7e1

Browse files
committed
Fix corruption of tableElts list by MergeAttributes().
Since commite7b3349, MergeAttributesdestructively modifies the input List, to which the caller'sCreateStmt still points. One may wonder whether this was already abug, but commitf0e4475 made thingsnoticeably worse by adding additional destructive modifications sothat the caller's List might, in the case of creation a partitionedtable, no longer even be structurally valid. Restore the status quoante by assigning the return value of MergeAttributes back tostmt->tableElts in the caller.In most of the places where DefineRelation is called, it doesn'tmatter what stmt->tableElts points to here or whether it's valid ornot, because the caller doesn't use the statement for anything afterDefineRelation returns anyway. However, ProcessUtilitySlow passes itto EventTriggerCollectSimpleCommand, and that function tries to invokecopyObject on it. If any of the CreateStmt's substructure is invalidat that point, undefined behavior will result.One might wonder whether this whole area needs further revision -perhaps DefineRelation() ought not to be destructively modifying thecaller-provided CreateStmt at all. However, that would be a behaviorchange for any event triggers using C code to inspect the CreateStmt,so for now, just fix the crash.Report by Amit Langote, who provided a somewhat different patch for it.Discussion:http://postgr.es/m/bf6a39a7-100a-74bd-1156-3c16a1429d88@lab.ntt.co.jp
1 parent7f17ae0 commitac8d7e1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
491491
{
492492
charrelname[NAMEDATALEN];
493493
OidnamespaceId;
494-
List*schema=stmt->tableElts;
495494
OidrelationId;
496495
OidtablespaceId;
497496
Relationrel;
@@ -614,19 +613,21 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
614613

615614
/*
616615
* Look up inheritance ancestors and generate relation schema, including
617-
* inherited attributes.
616+
* inherited attributes. (Note that stmt->tableElts is destructively
617+
* modified by MergeAttributes.)
618618
*/
619-
schema=MergeAttributes(schema,stmt->inhRelations,
620-
stmt->relation->relpersistence,
621-
stmt->partbound!=NULL,
622-
&inheritOids,&old_constraints,&parentOidCount);
619+
stmt->tableElts=
620+
MergeAttributes(stmt->tableElts,stmt->inhRelations,
621+
stmt->relation->relpersistence,
622+
stmt->partbound!=NULL,
623+
&inheritOids,&old_constraints,&parentOidCount);
623624

624625
/*
625626
* Create a tuple descriptor from the relation schema. Note that this
626627
* deals with column names, types, and NOT NULL constraints, but not
627628
* default values or CHECK constraints; we handle those below.
628629
*/
629-
descriptor=BuildDescForRelation(schema);
630+
descriptor=BuildDescForRelation(stmt->tableElts);
630631

631632
/*
632633
* Notice that we allow OIDs here only for plain tables and partitioned
@@ -667,7 +668,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
667668
cookedDefaults=NIL;
668669
attnum=0;
669670

670-
foreach(listptr,schema)
671+
foreach(listptr,stmt->tableElts)
671672
{
672673
ColumnDef*colDef=lfirst(listptr);
673674

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp