From: Mark Dilger <hornschnorter@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Checking return value of SPI_execute
Date: Tue, 5 Nov 2019 17:21:25 -0800
Message-ID: <17d30445-4862-7917-170f-84328dcd292d@gmail.com> (raw)
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.usAttachments:
[text/x-patch] v1-0001-Checking-return-value-of-SPI_execute.patch (1.3K, ../17d30445-4862-7917-170f-84328dcd292d@gmail.com/2-v1-0001-Checking-return-value-of-SPI_execute.patch)
download | inline diff:
From 5c4013e41fbe212e41116509c54a032e1b9ebc0d Mon Sep 17 00:00:00 2001
From: Mark Dilger <hornschnorter@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.cindex 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 instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: hornschnorter@gmail.com
Subject: Re: Checking return value of SPI_execute
In-Reply-To: <17d30445-4862-7917-170f-84328dcd292d@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox