]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix SPI_getvalue and SPI_getbinval to range-check the given attribute number
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Oct 2008 13:23:57 +0000 (13:23 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Oct 2008 13:23:57 +0000 (13:23 +0000)
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.

src/backend/executor/spi.c

index b95e72cc60ee50ff657f4260582f692c6c2b696b..b4794de89a03ae7ee552bb7346c1031be1fce341 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.107.2.1 2005/02/10 20:37:15 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.107.2.2 2008/10/16 13:23:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -559,7 +559,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;
@@ -609,7 +609,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;