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

Commit c27c399

Browse files
committed
Don't believe MinMaxExpr is leakproof without checking.
MinMaxExpr invokes the btree comparison function for its input datatype, so it's only leakproof if that function is. Many such functions are indeed leakproof, but others are not, and we should not just assume that they are. Hence, adjust contain_leaked_vars to verify the leakproofness of the referenced function explicitly. I didn't add a regression test because it would need to depend on some particular comparison function being leaky, and that's a moving target, per discussion. This has been wrong all along, so back-patch to supported branches. Discussion: https://postgr.es/m/31042.1546194242@sss.pgh.pa.us
1 parent b66a074 commit c27c399

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,6 @@ contain_leaked_vars_walker(Node *node, void *context)
14811481
case T_CaseExpr:
14821482
case T_CaseTestExpr:
14831483
case T_RowExpr:
1484-
case T_MinMaxExpr:
14851484
case T_NullTest:
14861485
case T_BooleanTest:
14871486
case T_List:
@@ -1536,6 +1535,36 @@ contain_leaked_vars_walker(Node *node, void *context)
15361535
}
15371536
break;
15381537

1538+
case T_MinMaxExpr:
1539+
{
1540+
/*
1541+
* MinMaxExpr is leakproof if the comparison function it calls
1542+
* is leakproof.
1543+
*/
1544+
MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
1545+
TypeCacheEntry *typentry;
1546+
bool leakproof;
1547+
1548+
/* Look up the btree comparison function for the datatype */
1549+
typentry = lookup_type_cache(minmaxexpr->minmaxtype,
1550+
TYPECACHE_CMP_PROC);
1551+
if (OidIsValid(typentry->cmp_proc))
1552+
leakproof = get_func_leakproof(typentry->cmp_proc);
1553+
else
1554+
{
1555+
/*
1556+
* The executor will throw an error, but here we just
1557+
* treat the missing function as leaky.
1558+
*/
1559+
leakproof = false;
1560+
}
1561+
1562+
if (!leakproof &&
1563+
contain_var_clause((Node *) minmaxexpr->args))
1564+
return true;
1565+
}
1566+
break;
1567+
15391568
case T_CurrentOfExpr:
15401569

15411570
/*

0 commit comments

Comments
 (0)