Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSA0s-0007cW-KY for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 01:21:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSA0r-0001NP-6o for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2019 01:21:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSA0q-0001NI-SA for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2019 01:21:32 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSA0o-0006SS-16 for pgsql-hackers@postgresql.org; Wed, 06 Nov 2019 01:21:32 +0000 Received: by mail-pg1-x530.google.com with SMTP id w11so5601692pga.12 for ; Tue, 05 Nov 2019 17:21:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=mBOvF6jLTmih3h2+CwVvA8CidePBXQEeVh35F5846Yw=; b=ZGoI5LrxQdSZTEyDPkSYBQR6NuMBy1M4uRWbMgp77TVv65BKSM8dEghJ120jzMinF6 hV8YUoa4UZVQGb5hDWu7u2B1D3oEusM3Qao+j1+9iwvX4JmZyJV+PtWB+9wy3kJk1yB8 husbz9QQmHV6tok6grX2Er0BaMoQSS010oXwUvUv9UlCZcEVdHfCFWYxRmKx54WICQVO NcTexSjNMyKDQwC0L5E8xH1if9i2ROup4q/VpRW84IEH8qK1bEDiE8GX1hRw/Kq+pLXD BTQC16USzpypFzxhL/he5Ad4mK1+hxA/wASVH0dPqSCxBtNE+A39Oi1iW2L2Hb8uHx33 xixw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=mBOvF6jLTmih3h2+CwVvA8CidePBXQEeVh35F5846Yw=; b=TDUBbbgf0NnD4syrMnRrjT/mog0fMD7KzfRhzX1Klo+Mfh6T78YSQOKi03C/lt8pT5 dwjNJlZwvGEJVWIsRX3zK8Bt3ucW39UC0UO4ZZt0BVXL/3hCwDer9MQwSEf36qSESFf2 hJVg6/9HJruGiYbnOENpoUu61tdgiuvrAPKfl+TGTpT+ZrgO2Xs+x1XYr0nmWDTUO7yg G3+ay2SBXfr2Ho5DLXyIp0rdpvg0EJHlJjLwAN7m2TCKCNmU6SjawrLZrXq0GNc754J6 0NFBkfhWs7NzAPBS2v61e1upfAVrpy5Q5ODCGnyQKfcKAalxejdOTpmv3yybX7L0iWBU FQuw== X-Gm-Message-State: APjAAAXtZ5BIQ6MjGvjvDAnKdOrQR5n790KkgvjOr6yhFZL0uWI33kfu lI8KZY0BrnsgaN1S6G0HVoPMKA/P X-Google-Smtp-Source: APXvYqxjJBzyt063epbkw+YCNy0U+ZJdvURT3XCBRFLqn1f4BEQnv293eB2Pfo5aJqewKrfmOaJjlg== X-Received: by 2002:a62:3786:: with SMTP id e128mr42276443pfa.11.1573003287220; Tue, 05 Nov 2019 17:21:27 -0800 (PST) Received: from [192.168.0.17] (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id i32sm13127968pgl.73.2019.11.05.17.21.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Nov 2019 17:21:26 -0800 (PST) To: PostgreSQL-development From: Mark Dilger Subject: Checking return value of SPI_execute Message-ID: <17d30445-4862-7917-170f-84328dcd292d@gmail.com> Date: Tue, 5 Nov 2019 17:21:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------CBA12726A0CEAD4E3CB622F7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------CBA12726A0CEAD4E3CB622F7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------CBA12726A0CEAD4E3CB622F7 Content-Type: text/x-patch; name="v1-0001-Checking-return-value-of-SPI_execute.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="v1-0001-Checking-return-value-of-SPI_execute.patch" From 5c4013e41fbe212e41116509c54a032e1b9ebc0d Mon Sep 17 00:00:00 2001 From: Mark Dilger 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 --------------CBA12726A0CEAD4E3CB622F7--