aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-07-01 11:40:22 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-07-01 11:40:33 -0400
commit0daeba0e927bfcb3d0ed9d510b84e555fc1e2741 (patch)
tree404fbba11c1a3b133e16a7f71b75c75573d744bc /src/backend/utils/adt/ruleutils.c
parent86437ddf8c8da6fff49bdf08a22af3460e078eeb (diff)
downloadpostgresql-0daeba0e927bfcb3d0ed9d510b84e555fc1e2741.tar.gz
postgresql-0daeba0e927bfcb3d0ed9d510b84e555fc1e2741.zip
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>
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index afc26d424fe..ffd2ca54e71 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -5967,7 +5967,8 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
tle = get_tle_by_resno(dpns->inner_tlist, var->varattno);
if (!tle)
- elog(ERROR, "bogus varattno for subquery var: %d", var->varattno);
+ elog(ERROR, "invalid attnum %d for relation \"%s\"",
+ var->varattno, rte->eref->aliasname);
Assert(netlevelsup == 0);
push_child_plan(dpns, dpns->inner_planstate, &save_dpns);
@@ -6028,9 +6029,13 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context)
else if (attnum > 0)
{
/* Get column name to use from the colinfo struct */
- Assert(attnum <= colinfo->num_cols);
+ if (attnum > colinfo->num_cols)
+ elog(ERROR, "invalid attnum %d for relation \"%s\"",
+ attnum, rte->eref->aliasname);
attname = colinfo->colnames[attnum - 1];
- Assert(attname != NULL);
+ if (attname == NULL) /* dropped column? */
+ elog(ERROR, "invalid attnum %d for relation \"%s\"",
+ attnum, rte->eref->aliasname);
}
else
{