summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2022-04-18 16:16:45 +0000
committerTom Lane2022-04-18 16:16:45 +0000
commit36d4efe779bfc7190ea1c1cf8deb0d945b726663 (patch)
tree7f542c402ab720ab0943472806506d4ed683b8f5
parent1a8b110539efe18803c1fa8aa452a2178dbad9a9 (diff)
Avoid invalid array reference in transformAlterTableStmt().
Don't try to look at the attidentity field of system attributes, because they're not there in the TupleDescAttr array. Sometimes this is harmless because we accidentally pick up a zero, but otherwise we'll report "no owned sequence found" from an attempt to alter a system attribute. (It seems possible that a SIGSEGV could occur, too, though I've not seen it in testing.) It's not in this function's charter to complain that you can't alter a system column, so instead just hard-wire an assumption that system attributes aren't identities. I didn't bother with a regression test because the appearance of the bug is very erratic. Per bug #17465 from Roman Zharkov. Back-patch to all supported branches. (There's not actually a live bug before v12, because before that get_attidentity() did the right thing anyway. But for consistency I changed the test in the older branches too.) Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/parser/parse_utilcmd.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 2826559d09..1a64a52279 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -3424,7 +3424,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
errmsg("column \"%s\" of relation \"%s\" does not exist",
cmd->name, RelationGetRelationName(rel))));
- if (TupleDescAttr(tupdesc, attnum - 1)->attidentity)
+ if (attnum > 0 &&
+ TupleDescAttr(tupdesc, attnum - 1)->attidentity)
{
Oid seq_relid = getIdentitySequence(relid, attnum, false);
Oid typeOid = typenameTypeId(pstate, def->typeName);