From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-committers@postgresql.org
Subject: Re: pgsql: PL/Python: Fix potential NULL pointer dereference
Date: Tue, 05 Dec 2017 14:45:59 -0500
Message-ID: <16695.1512503159@sss.pgh.pa.us> (raw)
In-Reply-To: <de6d3b84-287a-b943-b5cc-6f5825657c6b@2ndquadrant.com>
References: <E1eJin0-0002iK-Ge@gemulon.postgresql.org>
<26463.1511886937@sss.pgh.pa.us>
<a1f87b42-fd0c-e985-ff35-79e6ad5c890e@2ndquadrant.com>
<de6d3b84-287a-b943-b5cc-6f5825657c6b@2ndquadrant.com>
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 11/28/17 13:35, Peter Eisentraut wrote:
>> OK, I'll revert and rethink.
> How about this instead?
This looks better, but I think there are a couple more things:
* Seems like you ought to s/Py_DECREF(result)/Py_XDECREF(result)/ in the
PG_CATCH block (line 451 in HEAD). As this is coded, although result
is set to NULL within the PG_TRY, it doesn't seem possible for control
to reach PG_CATCH after that ... but that's a pretty fragile assumption.
* You'd also need to declare "result" as
PLyResultObject *volatile result;
if you intend to change it within the PG_TRY block.
On the whole it seems like it might be better to dodge this whole business
of changing "result" inside the TRY. You could do that if you did
something like
result->rows = PyList_New(rows);
- if (!result->rows)
- {
- Py_DECREF(result);
- result = NULL;
- }
- else
+ if (result->rows)
{
PLy_input_setup_tuple(&ininfo, tuptable->tupdesc,
and then add after the PG_END_TRY
if (!result->rows)
{
Py_DECREF(result);
result = NULL;
}
The repeated test is a bit annoying but maybe it's better than the
alternative. You'd probably need a comment explaining why it's
like that, though.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, peter.eisentraut@2ndquadrant.com
Subject: Re: pgsql: PL/Python: Fix potential NULL pointer dereference
In-Reply-To: <16695.1512503159@sss.pgh.pa.us>
References: <E1eJin0-0002iK-Ge@gemulon.postgresql.org> <26463.1511886937@sss.pgh.pa.us> <a1f87b42-fd0c-e985-ff35-79e6ad5c890e@2ndquadrant.com> <de6d3b84-287a-b943-b5cc-6f5825657c6b@2ndquadrant.com> <16695.1512503159@sss.pgh.pa.us>
* 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