1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Check for out-of-range varoattno in deparse_context_for_subplan.

I have seen this case in CVS tip due to new "physical tlist" optimization
for subqueries.  I believe it probably can't happen in existing releases,
but the check is not going to hurt anything, so backpatch to 8.0 just
in case.
This commit is contained in:
Tom Lane
2005-07-15 18:40:20 +00:00
parent 1e31942a33
commit 123e25b3a3

View File

@@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.188.4.1 2005/04/30 08:19:44 neilc Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.188.4.2 2005/07/15 18:40:20 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@@ -1500,13 +1500,19 @@ deparse_context_for_subplan(const char *name, List *tlist,
if (var->varnoold > 0 && var->varnoold <= rtablelength) if (var->varnoold > 0 && var->varnoold <= rtablelength)
{ {
RangeTblEntry *varrte = rt_fetch(var->varnoold, rtable); RangeTblEntry *varrte = rt_fetch(var->varnoold, rtable);
AttrNumber varattnum = var->varoattno;
/* need this test in case it's referencing a resjunk col */
if (varattnum <= list_length(varrte->eref->colnames))
{
char *varname; char *varname;
varname = get_rte_attribute_name(varrte, var->varoattno); varname = get_rte_attribute_name(varrte, varattnum);
attrs = lappend(attrs, makeString(varname)); attrs = lappend(attrs, makeString(varname));
continue; continue;
} }
} }
}
/* Fallback if can't get name */ /* Fallback if can't get name */
snprintf(buf, sizeof(buf), "?column%d?", resdom->resno); snprintf(buf, sizeof(buf), "?column%d?", resdom->resno);
attrs = lappend(attrs, makeString(pstrdup(buf))); attrs = lappend(attrs, makeString(pstrdup(buf)));