Skip to content

Commit 26f5613

Browse files
committed
SPI_exec shouldn't return SPI_OK_SELECT if it hasn't actually returned
a tuple table. Fixes core dump in pltcl (and probably other PLs) when executing a query rewritten by a rule. Per bug report from Wolfgang Walter.
1 parent 6976205 commit 26f5613

File tree

1 file changed

+14
-1
lines changed
  • src/backend/executor

1 file changed

+14
-1
lines changed

src/backend/executor/spi.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.84 2003/01/21 22:06:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.85 2003/01/29 15:24:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -124,6 +124,14 @@ SPI_finish(void)
124124
MemoryContextDelete(_SPI_current->execCxt);
125125
MemoryContextDelete(_SPI_current->procCxt);
126126

127+
/*
128+
* Reset result variables, especially SPI_tuptable which is probably
129+
* pointing at a just-deleted tuptable
130+
*/
131+
SPI_processed = 0;
132+
SPI_lastoid = InvalidOid;
133+
SPI_tuptable = NULL;
134+
127135
/*
128136
* After _SPI_begin_call _SPI_connected == _SPI_curid. Now we are
129137
* closing connection to SPI and returning to upper Executor and so
@@ -1314,6 +1322,11 @@ _SPI_pquery(QueryDesc *queryDesc, bool runit, int tcount)
13141322
SPI_lastoid = save_lastoid;
13151323
SPI_tuptable = _SPI_current->tuptable;
13161324
}
1325+
else if (res == SPI_OK_SELECT)
1326+
{
1327+
/* Don't return SPI_OK_SELECT if we discarded the result */
1328+
res = SPI_OK_UTILITY;
1329+
}
13171330

13181331
ExecutorEnd(queryDesc);
13191332

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