aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-16 13:23:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-16 13:23:34 +0000
commitb55073de28df0b3f401a4589646bb0489a1ceaf7 (patch)
treeedf749195924f84d7b885310ad33ffb082752e22 /src
parentc564931da0701d67f143b66a81f7d5fb1a906a6c (diff)
downloadpostgresql-b55073de28df0b3f401a4589646bb0489a1ceaf7.tar.gz
postgresql-b55073de28df0b3f401a4589646bb0489a1ceaf7.zip
Fix SPI_getvalue and SPI_getbinval to range-check the given attribute number
according to the TupleDesc's natts, not the number of physical columns in the tuple. The previous coding would do the wrong thing in cases where natts is different from the tuple's column count: either incorrectly report error when it should just treat the column as null, or actually crash due to indexing off the end of the TupleDesc's attribute array. (The second case is probably not possible in modern PG versions, due to more careful handling of inheritance cases than we once had. But it's still a clear lack of robustness here.) The incorrect error indication is ignored by all callers within the core PG distribution, so this bug has no symptoms visible within the core code, but it might well be an issue for add-on packages. So patch all the way back.
Diffstat (limited to 'src')
-rw-r--r--src/backend/executor/spi.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 7d4f84f5ad8..3515ee6e0b1 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165.2.4 2007/08/15 19:15:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.165.2.5 2008/10/16 13:23:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -654,7 +654,7 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
SPI_result = 0;
- if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
+ if (fnumber > tupdesc->natts || fnumber == 0 ||
fnumber <= FirstLowInvalidHeapAttributeNumber)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;
@@ -695,7 +695,7 @@ SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
{
SPI_result = 0;
- if (fnumber > tuple->t_data->t_natts || fnumber == 0 ||
+ if (fnumber > tupdesc->natts || fnumber == 0 ||
fnumber <= FirstLowInvalidHeapAttributeNumber)
{
SPI_result = SPI_ERROR_NOATTRIBUTE;