Skip to content

Commit cdf8b56

Browse files
committed
SPI_cursor_open failed to enforce that only read-only queries could be
executed in read_only mode. This could lead to various relatively-subtle failures, such as an allegedly stable function returning non-stable results. Bug goes all the way back to the introduction of read-only mode in 8.0. Per report from Gaetano Mendola.
1 parent e88a7ad commit cdf8b56

File tree

1 file changed

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

1 file changed

+25
-1
lines changed

src/backend/executor/spi.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.172 2007/03/15 23:12:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.173 2007/03/17 03:15:38 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -964,6 +964,30 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
964964
else
965965
portal->cursorOptions |= CURSOR_OPT_NO_SCROLL;
966966

967+
/*
968+
* If told to be read-only, we'd better check for read-only queries.
969+
* This can't be done earlier because we need to look at the finished,
970+
* planned queries. (In particular, we don't want to do it between
971+
* RevalidateCachedPlan and PortalDefineQuery, because throwing an error
972+
* between those steps would result in leaking our plancache refcount.)
973+
*/
974+
if (read_only)
975+
{
976+
ListCell *lc;
977+
978+
foreach(lc, stmt_list)
979+
{
980+
Node *pstmt = (Node *) lfirst(lc);
981+
982+
if (!CommandIsReadOnly(pstmt))
983+
ereport(ERROR,
984+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
985+
/* translator: %s is a SQL statement name */
986+
errmsg("%s is not allowed in a non-volatile function",
987+
CreateCommandTag(pstmt))));
988+
}
989+
}
990+
967991
/*
968992
* Set up the snapshot to use. (PortalStart will do CopySnapshot, so we
969993
* skip that here.)

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