Re: printf %s with NULL pointer (was Re: BUG #17098: Assert failed on composing an error message when adding a type to an extension being dropped) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: printf %s with NULL pointer (was Re: BUG #17098: Assert failed on composing an error message when adding a type to an extension being dropped)
Date
Msg-id 3233754.1626191526@sss.pgh.pa.us
Whole thread Raw
In response to Re: printf %s with NULL pointer (was Re: BUG #17098: Assert failed on composing an error message when adding a type to an extension being dropped)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I wrote:
> Now, what we don't have control of is what will happen in pre-v12
> branches on platforms where we use the system's *printf.  However,
> note what I wrote in the log for 0c62356cc:
>     Per commit e748e902d, we appear to have little or no coverage in the
>     buildfarm of machines that will dump core when asked to printf a
>     null string pointer.
> Thus it appears that a large fraction of the world is already either
> using glibc or following glibc's lead on this point.

Further to that point: I just ran around and verified that the system
printf prints "(null)" rather than crashing on FreeBSD 12.2, NetBSD 8.99,
OpenBSD 6.8, macOS 11.4, and Solaris 11.3.  AIX 7.2 and HPUX 10.20 print
"", but still don't crash.  If we change snprintf.c then we will also be
okay on Windows, because we've always used our own snprintf on that
platform.  In short, the only place I can find where there is actually
any hazard is Solaris 10 [1].  I do not think we should let the risk of
obscure bugs in pre-v12 versions on one obsolete OS drive our
decision-making about this.

            regards, tom lane

[1] Per experimentation locally and on the GCC compile farm, using
the attached.
#include <stdio.h>

int
main(int argc, char **argv)
{
    printf("NULL prints as \"%s\"\n", (char *) NULL);
    return 0;
}

pgsql-hackers by date:

Previous
From: Wu Haotian
Date:
Subject: Re: Add option --drop-cascade for pg_dump/restore
Next
From: Tomas Vondra
Date:
Subject: Re: proposal: possibility to read dumped table's name from file