Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJHI5-0003zY-Fj for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Nov 2017 11:09:33 +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 1eJHI4-0000Nd-MB for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Nov 2017 11:09:32 +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 1eJHI4-0000NT-Gw for pgsql-bugs@lists.postgresql.org; Mon, 27 Nov 2017 11:09:32 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eJHHx-0000oI-JH for pgsql-bugs@postgresql.org; Mon, 27 Nov 2017 11:09:32 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id vARB9Ivf007477; Mon, 27 Nov 2017 20:09:18 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 9EC6160294; Mon, 27 Nov 2017 20:09:18 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 938AA60292; Mon, 27 Nov 2017 20:09:18 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 8EE7640090E; Mon, 27 Nov 2017 20:09:18 +0900 (JST) Subject: Re: BUG #14929: Unchecked AllocateDir() return value in restoreTwoPhaseData() References: <20171127093107.1473.70477@wrigleys.postgresql.org> From: Amit Langote Message-ID: <9ac0d6ec-4ef7-4864-b141-985bb84fdc1a@lab.ntt.co.jp> Date: Mon, 27 Nov 2017 20:09:12 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit To: Michael Paquier , bianpan2016@163.com Cc: PostgreSQL mailing lists X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2017/11/27 19:53, Michael Paquier wrote: > On Mon, Nov 27, 2017 at 6:31 PM, wrote: >> AllocateDir() will return a NULL pointer if it fails to open the specified >> directory. However, in function restoreTwoPhaseData(), its return value is >> not checked. This may result in a NULL pointer dereference when trying to >> free it (see line 1759). > > You are missing the fact that ReadDir goes through ReadDirExtended, > which drops an ERROR log if the folder allocated is NULL. I noticed that too, but isn't possible that elevel might be such that we end up returning to restoreTwoPhaseData() after all and hit the line in it that will then dereference the NULL cldir? Maybe, that never happens because, elevel is never less than ERROR in that code path? Thanks, Amit