From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: TAKATSUKA Haruka <harukat@sraoss.co.jp>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #11335: an invalid prepare statement causes crash at log_statement = 'mod' or 'ddl'.
Date: Sat, 06 Sep 2014 16:25:28 -0400
Message-ID: <5731.1410035128@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHGQGwHhiBgw8zqi5S2CVwqNcZ_L4sMBivutbhwPufQEqvbpJA@mail.gmail.com>
References: <20140902111653.2936.35702@wrigleys.postgresql.org>
<CAHGQGwF8xRx0uNAXF3M=9SMJnLzNatBzbC8byXLNpgtTqRfu0Q@mail.gmail.com>
<CAHGQGwHhiBgw8zqi5S2CVwqNcZ_L4sMBivutbhwPufQEqvbpJA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Fujii Masao <masao.fujii@gmail.com> writes:
> On Thu, Sep 4, 2014 at 3:55 AM, Fujii Masao <masao.fujii@gmail.com> wrote:
>> Thanks for reporting the bug! This segmentation fault could reproduce
>> even on my machine. Barring any objection, I will apply the change that
>> you suggested.
> Done.
I don't think this fix is either appropriate or adequate. Stylistically,
it's bogus that this function should be prepared for a null argument when
similar command-tag-related functions right next to it are not. Moreover,
what is the reasoning why the correct answer for a null argument is
LOGSTMT_ALL and not something else? It'd be at least as legit to make
it LOGSTMT_NONE, for instance.
As far as adequacy goes, the actual bug seems to be that this bit of code
is not expecting a plansource's raw_parse_tree to ever be NULL:
/* Look through an EXECUTE to the referenced stmt */
ps = FetchPreparedStatement(stmt->name, false);
if (ps)
lev = GetCommandLogLevel(ps->plansource->raw_parse_tree);
else
lev = LOGSTMT_ALL;
and it is not terribly hard to find other places making the same
assumption, which is probably reasonable because the comments around
the plansource files don't suggest it's legal either. So I don't think
this has exhausted the number of ways to crash the backend after creating
such a prepared statement.
I think we should revert the patch as applied and instead think about
whether it's really legit to have a null raw_parse_tree in a cached plan.
If it is, the plansource comments need adjustment and so do several other
places in the code. I'd also say that the right place to adjust
GetCommandLogLevel is in the bit I quoted above, where we know that
what we're talking about is EXECUTE on an empty prepared query, and
so there's a more principled basis for determining what its logging
level ought to be.
It might be that we'd be better off inventing some kind of EmptyStmt
parse tree for this case. Or maybe we should reconsider whether
exec_parse_message should allow the case at all. It's not unreasonable
that Parse should require exactly one SQL statement, not just "at most
one".
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, masao.fujii@gmail.com, harukat@sraoss.co.jp
Subject: Re: BUG #11335: an invalid prepare statement causes crash at log_statement = 'mod' or 'ddl'.
In-Reply-To: <5731.1410035128@sss.pgh.pa.us>
References: <20140902111653.2936.35702@wrigleys.postgresql.org> <CAHGQGwF8xRx0uNAXF3M=9SMJnLzNatBzbC8byXLNpgtTqRfu0Q@mail.gmail.com> <CAHGQGwHhiBgw8zqi5S2CVwqNcZ_L4sMBivutbhwPufQEqvbpJA@mail.gmail.com> <5731.1410035128@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