From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Clough <greg.clough@enterprisedb.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Incorrect type in pg_cast causes Postmaster to core dump
Date: Fri, 21 Apr 2017 10:36:15 -0400
Message-ID: <12508.1492785375@sss.pgh.pa.us> (raw)
In-Reply-To: <CAE5uEHx0SC2hKCr=QX0-Hsv1b5wohCdK3CvYZjRrw7S++x=qpg@mail.gmail.com>
References: <CAE5uEHx0SC2hKCr=QX0-Hsv1b5wohCdK3CvYZjRrw7S++x=qpg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Greg Clough <greg.clough@enterprisedb.com> writes:
> I realise that my types were wrong (function returned an "integer", and
> should have returned a "numeric"), and I've fixed that and now it's working
> fine... but how can a type mismatch cause the entire cluster to crash?
Trivially. You told the system it should use "bool_to_num (boolean)
RETURNS integer" to coerce boolean to numeric, so it expected what
came out of the function to be numeric --- which is a pass-by-reference
type, so the Datum value should be a pointer, which something or other
would've tried to dereference. The actual value was just an integer
"1" though, which is not a valid pointer, so you got a SIGSEGV.
There are no training wheels for Postgres superusers. If you put
broken entries into the system catalogs using superuser powers,
you can break the database arbitrarily badly.
As Michael noted, the type compatibility check that's needed here
exists in CREATE CAST, not at runtime. CREATE CAST would have done
other essential housekeeping as well, such as creating a pg_depend
entry to prevent the function from being dropped out from under
the cast.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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, greg.clough@enterprisedb.com
Subject: Re: Incorrect type in pg_cast causes Postmaster to core dump
In-Reply-To: <12508.1492785375@sss.pgh.pa.us>
References: <CAE5uEHx0SC2hKCr=QX0-Hsv1b5wohCdK3CvYZjRrw7S++x=qpg@mail.gmail.com> <12508.1492785375@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