1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Fix unsafe reference into relcache in constructed CommentStmt.

The CommentStmt made by RebuildConstraintComment() has to pstrdup the
relation name, else it will contain a dangling pointer after that
relcache entry is flushed.  (I'm less sure that pstrdup'ing conname
is necessary, but let's be safe.)  Failure to do this leads to weird
errors or crashes, as reported by Marko Elezovic.

Bug introduced by commit e42375fc8, so back-patch to 9.5 as that was.

Fix by David Rowley, regression test by Michael Paquier

Discussion: https://postgr.es/m/DB6PR03MB30775D58E732D4EB0C13725B9AE00@DB6PR03MB3077.eurprd03.prod.outlook.com
This commit is contained in:
Tom Lane
2017-05-15 11:33:44 -04:00
parent f8dc1985fd
commit 12590c5d33
3 changed files with 53 additions and 2 deletions

View File

@ -9764,8 +9764,8 @@ RebuildConstraintComment(AlteredTableInfo *tab, int pass, Oid objid,
cmd = makeNode(CommentStmt);
cmd->objtype = OBJECT_TABCONSTRAINT;
cmd->object = (Node *) list_make3(makeString(get_namespace_name(RelationGetNamespace(rel))),
makeString(RelationGetRelationName(rel)),
makeString(conname));
makeString(pstrdup(RelationGetRelationName(rel))),
makeString(pstrdup(conname)));
cmd->comment = comment_str;
/* Append it to list of commands */