]> granicus.if.org Git - postgresql/commit
Fix corner-case failures in has_foo_privilege() family of functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2018 15:54:12 +0000 (11:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Oct 2018 15:54:12 +0000 (11:54 -0400)
commit6d73983be61adde122b876308dbc6b6d52113419
tree2b147fe3f3e8c9735dc75f3825b1d4b27e4280b5
parent0353f48f0e7c85bc1a053710ed42ab23123b0b7c
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
src/backend/utils/adt/acl.c
src/test/regress/expected/privileges.out
src/test/regress/sql/privileges.sql