Re: Incorrect type in pg_cast causes Postmaster to core dump

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Clough <greg(dot)clough(at)enterprisedb(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Incorrect type in pg_cast causes Postmaster to core dump
Date: 2017-04-21 14:36:15
Message-ID: 12508.1492785375@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Greg Clough <greg(dot)clough(at)enterprisedb(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2017-04-21 16:15:32 Re: ON CONFLICT issie detected
Previous Message Michael Paquier 2017-04-21 13:26:09 Re: Incorrect type in pg_cast causes Postmaster to core dump