Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XQMYD-000733-Od for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Sep 2014 20:25:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XQMYC-0002Co-Hp for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Sep 2014 20:25:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XQMYB-0002Ci-Vm for pgsql-bugs@postgresql.org; Sat, 06 Sep 2014 20:25:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XQMY8-0007lk-Ev for pgsql-bugs@postgresql.org; Sat, 06 Sep 2014 20:25:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s86KPSn0005732; Sat, 6 Sep 2014 16:25:28 -0400 From: Tom Lane To: Fujii Masao cc: TAKATSUKA Haruka , pgsql-bugs Subject: Re: BUG #11335: an invalid prepare statement causes crash at log_statement = 'mod' or 'ddl'. In-reply-to: References: <20140902111653.2936.35702@wrigleys.postgresql.org> Comments: In-reply-to Fujii Masao message dated "Fri, 05 Sep 2014 02:33:48 +0900" Date: Sat, 06 Sep 2014 16:25:28 -0400 Message-ID: <5731.1410035128@sss.pgh.pa.us> X-Pg-Spam-Score: -3.6 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Fujii Masao writes: > On Thu, Sep 4, 2014 at 3:55 AM, Fujii Masao 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