Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b2c740c

Browse files
committed
Avoid scribbling on input node tree in CREATE/ALTER DOMAIN.
This works fine in the "simple Query" code path; but if the statement is in the plan cache then it's corrupted for future re-execution. Apply copyObject() to protect the original tree from modification, as we've done elsewhere. This narrow fix is applied only to the back branches. In HEAD, the problem was fixed more generally by commit 7c337b6; but that changed ProcessUtility's API, so it's infeasible to back-patch. Per bug #17053 from Charles Samborski. Discussion: https://postgr.es/m/931771.1623893989@sss.pgh.pa.us Discussion: https://postgr.es/m/17053-3ca3f501bbc212b4@postgresql.org
1 parent 6432bfe commit b2c740c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/backend/commands/typecmds.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,12 @@ DefineDomain(CreateDomainStmt *stmt)
912912
pstate = make_parsestate(NULL);
913913

914914
/*
915-
* Cook the constr->raw_expr into an expression. Note:
916-
* name is strictly for error message
915+
* Cook the constr->raw_expr into an expression; copy it
916+
* in case the input is in plan cache. Note: name is used
917+
* only for error messages.
917918
*/
918-
defaultExpr = cookDefault(pstate, constr->raw_expr,
919+
defaultExpr = cookDefault(pstate,
920+
copyObject(constr->raw_expr),
919921
basetypeoid,
920922
basetypeMod,
921923
domainName,
@@ -2248,10 +2250,10 @@ AlterDomainDefault(List *names, Node *defaultRaw)
22482250
pstate = make_parsestate(NULL);
22492251

22502252
/*
2251-
* Cook the colDef->raw_expr into an expression. Note: Name is
2252-
* strictly for error message
2253+
* Cook the raw default into an expression; copy it in case the input
2254+
* is in plan cache. Note: name is used only for error messages.
22532255
*/
2254-
defaultExpr = cookDefault(pstate, defaultRaw,
2256+
defaultExpr = cookDefault(pstate, copyObject(defaultRaw),
22552257
typTup->typbasetype,
22562258
typTup->typtypmod,
22572259
NameStr(typTup->typname),
@@ -3140,7 +3142,12 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
31403142
pstate->p_pre_columnref_hook = replace_domain_constraint_value;
31413143
pstate->p_ref_hook_state = (void *) domVal;
31423144

3143-
expr = transformExpr(pstate, constr->raw_expr, EXPR_KIND_DOMAIN_CHECK);
3145+
/*
3146+
* Transform the expression; first we must copy the input, in case it's in
3147+
* plan cache.
3148+
*/
3149+
expr = transformExpr(pstate, copyObject(constr->raw_expr),
3150+
EXPR_KIND_DOMAIN_CHECK);
31443151

31453152
/*
31463153
* Make sure it yields a boolean result.

0 commit comments

Comments
 (0)