[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pgsql-committers
Subject:    pgsql: Fix List memory issue in transformColumnDefinition
From:       David Rowley <drowley () postgresql ! org>
Date:       2023-03-30 23:15:27
Message-ID: E1pi1UM-000Xl3-Nr () gemulon ! postgresql ! org
[Download RAW message or body]

[Attachment #2 (text/plain)]

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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/33510bc64919b980433440340bc154e90af64e73

Modified Files
--------------
src/backend/parser/parse_utilcmd.c | 3 +++
1 file changed, 3 insertions(+)



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic