Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJTis-0000Dp-T0 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 00:26:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJTis-0007F9-Em for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 00:26:02 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJTis-0007Eu-93 for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2017 00:26:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJTin-0001hS-Pk for pgsql-bugs@postgresql.org; Tue, 28 Nov 2017 00:26:01 +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 vAS0Pnt4019182; Mon, 27 Nov 2017 19:25:49 -0500 From: Tom Lane To: Amit Langote cc: bianpan2016@163.com, pgsql-bugs@postgresql.org Subject: Re: BUG #14928: Unchecked SearchSysCacheCopy1() return value In-reply-to: <85682287-8cdb-03d5-94d3-2b722e3ce968@lab.ntt.co.jp> References: <20171127091341.1468.72696@wrigleys.postgresql.org> <85682287-8cdb-03d5-94d3-2b722e3ce968@lab.ntt.co.jp> Comments: In-reply-to Amit Langote message dated "Mon, 27 Nov 2017 19:21:32 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19180.1511828749.1@sss.pgh.pa.us> Date: Mon, 27 Nov 2017 19:25:49 -0500 Message-ID: <19181.1511828749@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > On 2017/11/27 18:13, bianpan2016@163.com wrote: >> Function SearchSysCacheCopy1() may return a NULL pointer if there is no >> enough memory. But in function ATExecDetachPartition(), its return value is >> not checked, which may result in NULL dereference (see line 13818). > Thanks for the report. Attached a patch that adds a check that tuple is > valid before trying to dereference it. Pushed. Checking other SearchSysCache calls in these two files, I noted a third instance of the same problem in StorePartitionKey(). However, looking closer, StorePartitionKey never does anything at all with the result of its SearchSysCache1(PARTRELID, ...) lookup, including never releasing the syscache reference. How is it that we don't get refcount leak warnings? I guess that must prove that that lookup always fails, which is not too surprising since it seems to be against the partition key info that we haven't stored yet. Anyway, I just diked that one out, since it's clearly useless. regards, tom lane