From: Tom Lane <tgl@sss.pgh.pa.us>
To: vignesh C <vignesh21@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: initdb SegFault
Date: Tue, 19 Nov 2019 10:16:02 -0500
Message-ID: <7379.1574176562@sss.pgh.pa.us> (raw)
In-Reply-To: <CALDaNm0ubwYDzbdYG5ezr6_qLodFM7KGoUJJJQQOBXe6_r=ZEQ@mail.gmail.com>
References: <CALDaNm0ubwYDzbdYG5ezr6_qLodFM7KGoUJJJQQOBXe6_r=ZEQ@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, vignesh21@gmail.com, pgsql-hackers@postgresql.org
Subject: Re: initdb SegFault
In-Reply-To: <7379.1574176562@sss.pgh.pa.us>
References: <CALDaNm0ubwYDzbdYG5ezr6_qLodFM7KGoUJJJQQOBXe6_r=ZEQ@mail.gmail.com> <7379.1574176562@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox