Skip to content

Commit 184ba4d

Browse files
committed
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.
1 parent 0182951 commit 184ba4d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* back to source text
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.203 2005/07/02 17:01:50 momjian Exp $
6+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.204 2005/07/15 18:39:59 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1510,11 +1510,17 @@ deparse_context_for_subplan(const char *name, List *tlist,
15101510
if (var->varnoold > 0 && var->varnoold <= rtablelength)
15111511
{
15121512
RangeTblEntry *varrte = rt_fetch(var->varnoold, rtable);
1513-
char *varname;
1513+
AttrNumber varattnum = var->varoattno;
15141514

1515-
varname = get_rte_attribute_name(varrte, var->varoattno);
1516-
attrs = lappend(attrs, makeString(varname));
1517-
continue;
1515+
/* need this test in case it's referencing a resjunk col */
1516+
if (varattnum <= list_length(varrte->eref->colnames))
1517+
{
1518+
char *varname;
1519+
1520+
varname = get_rte_attribute_name(varrte, varattnum);
1521+
attrs = lappend(attrs, makeString(varname));
1522+
continue;
1523+
}
15181524
}
15191525
}
15201526
/* Fallback if can't get name */

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