Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iiMaH-00033a-Re for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Dec 2019 18:01:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iiMaG-00016q-Jx for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Dec 2019 18:01:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iiMaG-00016j-8M for pgsql-bugs@lists.postgresql.org; Fri, 20 Dec 2019 18:01:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iiMaE-0000ZK-2l for pgsql-bugs@lists.postgresql.org; Fri, 20 Dec 2019 18:01:03 +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 xBKI0xdY008639; Fri, 20 Dec 2019 13:00:59 -0500 From: Tom Lane To: ipluta@wp.pl cc: pgsql-bugs@lists.postgresql.org, Joe Conway Subject: Re: BUG #16176: NULL value returned by category_sql argument to crosstab() causes segmentation fault In-reply-to: <16176-7489719b05e4303c@postgresql.org> References: <16176-7489719b05e4303c@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 20 Dec 2019 17:25:56 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8637.1576864859.1@sss.pgh.pa.us> Date: Fri, 20 Dec 2019 13:00:59 -0500 Message-ID: <8638.1576864859@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > -- this will crash pg12, but not version() < 12 - note NULL value in > categories query: > select * from crosstab ('values (1, 2, 12), (1, 3, 13), (2, 2, 22), (2, > 3, 23), (3, 2, 32), (3, 3, 33) order by 1, 2, 3', 'values (2), (null)') as > rr (a int, "2" int, "3" int); Yeah, duplicated here. It seems tablefunc is passing a NULL string pointer to sprintf(). Previously, that would work on some platforms and crash on others --- as of v12, it crashes everywhere. What we need here is to figure out what the hashtab string key ought to be for a NULL category. I suspect what was happening before (on non-crashing platforms) was that you implicitly got "(nil)" or some spelling like that, which is not great because it could conflict with a valid user key. Alternatively, we could refuse NULL category values ... not sure if that's desirable. Anyway, this is *not* a new bug, it's just possible to hit it on more platforms now. regards, tom lane