Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdz2J-0001SE-Qp for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jul 2018 14:27:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdz2I-0001iJ-B1 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jul 2018 14:27:06 +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.89) (envelope-from ) id 1fdz2I-0001iA-3b for pgsql-hackers@lists.postgresql.org; Fri, 13 Jul 2018 14:27:06 +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 1fdz2F-0008Tq-ET for pgsql-hackers@postgresql.org; Fri, 13 Jul 2018 14:27:05 +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 w6DEQu1q000994; Fri, 13 Jul 2018 10:26:57 -0400 From: Tom Lane To: Pierre Ducroquet cc: pgsql-hackers@postgresql.org, Oleg Bartunov , Teodor Sigaev Subject: Re: function lca('{}'::ltree[]) caused DB Instance crash In-reply-to: <4285558.KOck4HGOto@peanuts2> References: <5b0d8e4f-f2a3-1305-d612-e00e35a7be66@qunar.com> <4285558.KOck4HGOto@peanuts2> Comments: In-reply-to Pierre Ducroquet message dated "Fri, 13 Jul 2018 12:48:35 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <992.1531492016.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 13 Jul 2018 10:26:56 -0400 Message-ID: <993.1531492016@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Pierre Ducroquet writes: > On Friday, July 13, 2018 12:09:20 PM CEST 李海龙 wrote: >> contrib_regression=# select lca('{}'::ltree[]); >> server closed the connection unexpectedly > There is indeed a bug. The _lca function in _ltree_op.c tries to allocate 0 > bytes of memory, doesn't initialize it and dereference it in lca_inner. > The attached basic patch fixes it. I think the defense ought to be in lca_inner not there. However, I don't understand why this code is returning NULL, rather than a zero-length ltree, in the case that there's no common prefix. That doesn't seem consistent to me. regards, tom lane