aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2023-03-31 12:15:07 +1300
committerDavid Rowley <drowley@postgresql.org>2023-03-31 12:15:07 +1300
commit33510bc64919b980433440340bc154e90af64e73 (patch)
tree0b44b555c8e1f627716e8623a3b8138b5e0d92f6 /src/backend/parser/parse_utilcmd.c
parentd2a1d4b190ec4ad6afa6dfee672e743d906f4965 (diff)
downloadpostgresql-33510bc64919b980433440340bc154e90af64e73.tar.gz
postgresql-33510bc64919b980433440340bc154e90af64e73.zip
Fix List memory issue in transformColumnDefinition
When calling generateSerialExtraStmts(), we would pass in the constraint->options. In some cases, generateSerialExtraStmts() would modify the referenced List to remove elements from it, but doing so is invalid without assigning the list back to all variables that point to it. In the particular reported problem case, the List became empty, in which cases it became NIL, but the passed in constraint->options didn't get to find out about that and was left pointing to free'd memory. To fix this, just perform a list_copy() inside generateSerialExtraStmts(). We could just do a list_copy() just before we perform the delete from the list, however, that seems less robust. Let's make sure the generated CreateSeqStmt gets a completely different copy of the list to be safe. Bug: #17879 Reported-by: Fei Changhong Diagnosed-by: Fei Changhong Discussion: https://postgr.es/m/17879-b7dfb5debee58ff5@postgresql.org Backpatch-through: 11, all supported versions
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index a95dcf19360..b19037ace3c 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -386,6 +386,9 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
AlterSeqStmt *altseqstmt;
List *attnamelist;
+ /* Make a copy of this as we may end up modifying it in the code below */
+ seqoptions = list_copy(seqoptions);
+
/*
* Determine namespace and name to use for the sequence.
*