Skip to content

Commit 0daeba0

Browse files
committed
Be more paranoid in ruleutils.c's get_variable().
We were merely Assert'ing that the Var matched the RTE it's supposedly from. But if the user passes incorrect information to pg_get_expr(), the RTE might in fact not match; this led either to Assert failures or core dumps, as reported by Chris Hanks in bug #14220. To fix, just convert the Asserts to test-and-elog. Adjust an existing test-and-elog elsewhere in the same function to be consistent in wording. (If we really felt these were user-facing errors, we might promote them to ereport's; but I can't convince myself that they're worth translating.) Back-patch to 9.3; the problematic code doesn't exist before that, and a quick check says that 9.2 doesn't crash on such cases. Michael Paquier and Thomas Munro Report: <20160629224349.1407.32667@wrigleys.postgresql.org>
1 parent 86437dd commit 0daeba0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5967,7 +5967,8 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
59675967

59685968
tle = get_tle_by_resno(dpns->inner_tlist, var->varattno);
59695969
if (!tle)
5970-
elog(ERROR, "bogus varattno for subquery var: %d", var->varattno);
5970+
elog(ERROR, "invalid attnum %d for relation \"%s\"",
5971+
var->varattno, rte->eref->aliasname);
59715972

59725973
Assert(netlevelsup == 0);
59735974
push_child_plan(dpns, dpns->inner_planstate, &save_dpns);
@@ -6028,9 +6029,13 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
60286029
else if (attnum > 0)
60296030
{
60306031
/* Get column name to use from the colinfo struct */
6031-
Assert(attnum <= colinfo->num_cols);
6032+
if (attnum > colinfo->num_cols)
6033+
elog(ERROR, "invalid attnum %d for relation \"%s\"",
6034+
attnum, rte->eref->aliasname);
60326035
attname = colinfo->colnames[attnum - 1];
6033-
Assert(attname != NULL);
6036+
if (attname == NULL) /* dropped column? */
6037+
elog(ERROR, "invalid attnum %d for relation \"%s\"",
6038+
attnum, rte->eref->aliasname);
60346039
}
60356040
else
60366041
{

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