Re: initdb SegFault - Mailing list pgsql-hackers

From Tom Lane
Subject Re: initdb SegFault
Date
Msg-id 7379.1574176562@sss.pgh.pa.us
Whole thread Raw
In response to initdb SegFault  (vignesh C <vignesh21@gmail.com>)
Responses Re: initdb SegFault  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
vignesh C <vignesh21@gmail.com> writes:
> createPQExpBuffer allocates memory and returns the pointer, there is a
> possibility that createPQExpBuffer can return NULL pointer in case of
> malloc failiure, but initdb's main function does not check this
> condition. During malloc failure when pointer is accessed it results
> in segmentation fault. Made changes to check and exit if
> createPQExpBuffer return's NULL pointer. Patch for the same is
> attached.

I can't get excited about this, for several reasons.

1) The probability of it happening in the field is not
distinguishable from zero, surely.  I imagine you forced this
failure by making a debugging malloc fail occasionally.

2) If we really are out of memory at this point, we'd have just as good
odds that some allocation request inside pg_log_error() would fail.
There's no practical way to ensure that that code path remains free
of malloc attempts.  (Not to mention cleanup_directories_atexit().)

3) In the end, an initdb failure is an initdb failure.  This change
doesn't improve robustness by any useful metric, it just adds an
untestable code path.  If we could recover somehow, it'd be more
interesting to spend time on.

BTW, looking at the small minority of places that bother to test
for createPQExpBuffer failure, the correct test for that seems
to be PQExpBufferBroken().

            regards, tom lane



pgsql-hackers by date:

Previous
From: Nicolas Lutic
Date:
Subject: Re: PITR on DROP DATABASE, deleting of the database directory despitethe recovery_target_time set before.
Next
From: Andres Freund
Date:
Subject: Re: initdb SegFault