Skip to content

Commit 2f1997b

Browse files
committed
Teach contain_leaked_vars that assignment SubscriptingRefs are leaky.
array_get_element and array_get_slice qualify as leakproof, since they will silently return NULL for bogus subscripts. But array_set_element and array_set_slice throw errors for such cases, making them clearly not leakproof. contain_leaked_vars was evidently written with only the former case in mind, as it gave the wrong answer for assignment SubscriptingRefs (nee ArrayRefs). This would be a live security bug, were it not that assignment SubscriptingRefs can only occur in INSERT and UPDATE target lists, while we only care about leakproofness for qual expressions; so the wrong answer can't occur in practice. Still, that's a rather shaky answer for a security-related question; and maybe in future somebody will want to ask about leakproofness of a tlist. So it seems wise to fix and even back-patch this correction. (We would need some change here anyway for the upcoming generic-subscripting patch, since extensions might make different tradeoffs about whether to throw errors. Commit 558d77f attempted to lay groundwork for that by asking check_functions_in_node whether a SubscriptingRef contains leaky functions; but that idea fails now that the implementation methods of a SubscriptingRef are not SQL-visible functions that could be marked leakproof or not.) Back-patch to 9.6. While 9.5 has the same issue, the code's a bit different. It seems quite unlikely that we'd introduce any actual bug in the short time 9.5 has left to live, so the work/risk/reward balance isn't attractive for changing 9.5. Discussion: https://postgr.es/m/3143742.1607368115@sss.pgh.pa.us
1 parent e824ddc commit 2f1997b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,6 @@ contain_leaked_vars_walker(Node *node, void *context)
14111411
case T_ScalarArrayOpExpr:
14121412
case T_CoerceViaIO:
14131413
case T_ArrayCoerceExpr:
1414-
case T_SubscriptingRef:
14151414

14161415
/*
14171416
* If node contains a leaky function call, and there's any Var
@@ -1423,6 +1422,23 @@ contain_leaked_vars_walker(Node *node, void *context)
14231422
return true;
14241423
break;
14251424

1425+
case T_SubscriptingRef:
1426+
{
1427+
SubscriptingRef *sbsref = (SubscriptingRef *) node;
1428+
1429+
/*
1430+
* subscripting assignment is leaky, but subscripted fetches
1431+
* are not
1432+
*/
1433+
if (sbsref->refassgnexpr != NULL)
1434+
{
1435+
/* Node is leaky, so reject if it contains Vars */
1436+
if (contain_var_clause(node))
1437+
return true;
1438+
}
1439+
}
1440+
break;
1441+
14261442
case T_RowCompareExpr:
14271443
{
14281444
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy