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:28 +0000 (13:23 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Oct 2008 13:23:28 +0000 (13:23 +0000)
commitb9053b1e6a601a8d3ba3379eae11459dbea5e845
treefb88badf2ceec0970c30e01677c9e1bbc620ca95
parent7494c0e0d4762e7df4d4d8d7081fb4117d3c3cdd
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.
src/backend/executor/spi.c