Hackers,

please find attached a patch fixing a problem previously discussed [1] about the code inappropriately ignoring the return value from SPI_execute.

I will be adding this to https://commitfest.postgresql.org/26/ shortly.

Mark Dilger

[1] https://www.postgresql.org/message-id/24753.1558141935%40sss.pgh.pa.us
>From 5c4013e41fbe212e41116509c54a032e1b9ebc0d Mon Sep 17 00:00:00 2001
From: Mark Dilger <hornschnor...@gmail.com>
Date: Tue, 5 Nov 2019 16:40:58 -0800
Subject: [PATCH v1] Checking return value of SPI_execute.

In query_to_oid_list, the return code from SPI_execute was ignored.  I
know of no case where this manifests as a live bug, since the query
strings passed into query_to_oid_list appear to always succeed (and are
not user supplied).  Even so, ignoring the return code seems poor form
and could be a source of bugs if surrounding code were to change.

See discussion with Tom Lane near the end of
https://www.postgresql.org/message-id/24753.1558141935%40sss.pgh.pa.us
---
 src/backend/utils/adt/xml.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 3a493dd6bf..ff0577fc0b 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -2461,8 +2461,11 @@ query_to_oid_list(const char *query)
 {
 	uint64		i;
 	List	   *list = NIL;
+	int			spi_result;
 
-	SPI_execute(query, true, 0);
+	spi_result = SPI_execute(query, true, 0);
+	if (spi_result < 0)
+		elog(ERROR, "SPI_execute returned %s", SPI_result_code_string(spi_result));
 
 	for (i = 0; i < SPI_processed; i++)
 	{
-- 
2.20.1

Reply via email to