pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix corner-case failures in has_foo_privilege() family of functi
Date: Tue, 02 Oct 2018 15:54:59 +0000
Message-ID: <E1g7N0l-0000Vq-DI@gemulon.postgresql.org> (raw)

Fix corner-case failures in has_foo_privilege() family of functions.

The variants of these functions that take numeric inputs (OIDs or
column numbers) are supposed to return NULL rather than failing
on bad input; this rule reduces problems with snapshot skew when
queries apply the functions to all rows of a catalog.

has_column_privilege() had careless handling of the case where the
table OID didn't exist.  You might get something like this:
        select has_column_privilege(9999,'nosuchcol','select');
        ERROR:  column "nosuchcol" of relation "(null)" does not exist
or you might get a crash, depending on the platform's printf's response
to a null string pointer.

In addition, while applying the column-number variant to a dropped
column returned NULL as desired, applying the column-name variant
did not:
        select has_column_privilege('mytable','........pg.dropped.2........','select');
        ERROR:  column "........pg.dropped.2........" of relation "mytable" does not exist
It seems better to make this case return NULL as well.

Also, the OID-accepting variants of has_foreign_data_wrapper_privilege,
has_server_privilege, and has_tablespace_privilege didn't follow the
principle of returning NULL for nonexistent OIDs.  Superusers got TRUE,
everybody else got an error.

Per investigation of Jaime Casanova's report of a new crash in HEAD.
These behaviors have been like this for a long time, so back-patch to
all supported branches.

Patch by me; thanks to Stephen Frost for discussion and review

Discussion: https://postgr.es/m/CAJGNTeP=-6Gyqq5TN9OvYEydi7Fv1oGyYj650LGTnW44oAzYCg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3d0f68dd30612db8d8cf6529455a369ad121c521

Modified Files
--------------
src/backend/utils/adt/acl.c              | 95 ++++++++++++++++++++++++++++----
src/test/regress/expected/privileges.out | 57 +++++++++++++++++++
src/test/regress/sql/privileges.sql      | 17 ++++++
3 files changed, 159 insertions(+), 10 deletions(-)



view thread (7+ messages)

Message-ID: <E1g7N0l-0000Vq-DI@gemulon.postgresql.org>
Permalink:  ../E1g7N0l-0000Vq-DI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1g7N0l-0000Vq-DI@gemulon.postgresql.org

 · 

reply

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix corner-case failures in has_foo_privilege() family of functi
  In-Reply-To: <E1g7N0l-0000Vq-DI@gemulon.postgresql.org>
  References: <E1g7N0l-0000Vq-DI@gemulon.postgresql.org>

* 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