Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1c92724

Browse files
committed
Set read_only = TRUE while evaluating input queries for ts_rewrite()
and ts_stat(), per my recent suggestion. Also add a possibly-not-needed- but-can't-hurt check for NULL SPI_tuptable, before we try to dereference same.
1 parent 592c88a commit 1c92724

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/backend/utils/adt/tsquery_rewrite.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.6 2007/10/24 02:24:47 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_rewrite.c,v 1.7 2007/10/24 03:30:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -259,7 +259,7 @@ tsquery_rewrite_query(PG_FUNCTION_ARGS)
259259
MemoryContext oldcontext;
260260
QTNode *tree;
261261
char *buf;
262-
void *plan;
262+
SPIPlanPtr plan;
263263
Portal portal;
264264
bool isnull;
265265
int i;
@@ -281,12 +281,13 @@ tsquery_rewrite_query(PG_FUNCTION_ARGS)
281281
if ((plan = SPI_prepare(buf, 0, NULL)) == NULL)
282282
elog(ERROR, "SPI_prepare(\"%s\") failed", buf);
283283

284-
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, false)) == NULL)
284+
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, true)) == NULL)
285285
elog(ERROR, "SPI_cursor_open(\"%s\") failed", buf);
286286

287287
SPI_cursor_fetch(portal, true, 100);
288288

289-
if (SPI_tuptable->tupdesc->natts != 2 ||
289+
if (SPI_tuptable == NULL ||
290+
SPI_tuptable->tupdesc->natts != 2 ||
290291
SPI_gettypeid(SPI_tuptable->tupdesc, 1) != TSQUERYOID ||
291292
SPI_gettypeid(SPI_tuptable->tupdesc, 2) != TSQUERYOID)
292293
ereport(ERROR,

src/backend/utils/adt/tsvector_op.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.6 2007/10/23 00:51:23 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.7 2007/10/24 03:30:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1088,19 +1088,20 @@ ts_stat_sql(text *txt, text *ws)
10881088
*stat;
10891089
bool isnull;
10901090
Portal portal;
1091-
void *plan;
1091+
SPIPlanPtr plan;
10921092

10931093
if ((plan = SPI_prepare(query, 0, NULL)) == NULL)
10941094
/* internal error */
10951095
elog(ERROR, "SPI_prepare(\"%s\") failed", query);
10961096

1097-
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, false)) == NULL)
1097+
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, true)) == NULL)
10981098
/* internal error */
10991099
elog(ERROR, "SPI_cursor_open(\"%s\") failed", query);
11001100

11011101
SPI_cursor_fetch(portal, true, 100);
11021102

1103-
if (SPI_tuptable->tupdesc->natts != 1 ||
1103+
if (SPI_tuptable == NULL ||
1104+
SPI_tuptable->tupdesc->natts != 1 ||
11041105
SPI_gettypeid(SPI_tuptable->tupdesc, 1) != TSVECTOROID)
11051106
ereport(ERROR,
11061107
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

0 commit comments

Comments
 (0)