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 1iigN7-0002mr-MC for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Dec 2019 15:08:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iigN6-00072G-EP for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Dec 2019 15:08:48 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iigN6-000729-6P for pgsql-bugs@lists.postgresql.org; Sat, 21 Dec 2019 15:08:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iigMz-0007cw-MX for pgsql-bugs@lists.postgresql.org; Sat, 21 Dec 2019 15:08:47 +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 xBLF8bxp012401; Sat, 21 Dec 2019 10:08:38 -0500 From: Tom Lane To: Joe Conway cc: ipluta@wp.pl, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16176: NULL value returned by category_sql argument to crosstab() causes segmentation fault In-reply-to: <8d8ef71e-a347-67be-696a-3bdd259ec9fb@joeconway.com> References: <16176-7489719b05e4303c@postgresql.org> <8638.1576864859@sss.pgh.pa.us> <8d8ef71e-a347-67be-696a-3bdd259ec9fb@joeconway.com> Comments: In-reply-to Joe Conway message dated "Sat, 21 Dec 2019 09:14:41 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12399.1576940917.1@sss.pgh.pa.us> Date: Sat, 21 Dec 2019 10:08:37 -0500 Message-ID: <12400.1576940917@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Joe Conway writes: > It appears that in pg11 (and presumably prior) when snprintf() is called > it is resolved (here at least )to __GI___snprintf() which comes directly > from libc. On my desktop machine the system snprintf() deals with a null > pointer argument without crashing. I guess this is why the crash was > platform dependent. Right, glibc's version of snprintf has produced "(nil)" or "(null)" or something like that for many years. I'm not sure if that's true among the BSDen. One place where the platform snprintf does *not* survive this case is Windows. > In pg12 (and presumably master), it is resolved to our own port function > pg_snprintf(), which in turn works its way to dopr(), where strlen() is > called on a null pointer and "". Right. While it would only take a couple more lines of code to act like glibc does, we intentionally adopted the stricter definition because it seemed more likely to expose bugs. Looks like it just did. > From what I can see, even on pg11 and prior, having a null category > never did anything useful. And in the 16 years or so since this has been > around, no one in my memory ever asked for that functionality, so I am > inclined to refuse NULL category values unless someone wants to make a > good case otherwise. WFM, but I've never used crosstab() much so I don't have a good feeling for significant use-cases. regards, tom lane