pgsql: Fix corner-case failures in has_foo_privilege() family offuncti

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix corner-case failures in has_foo_privilege() family offuncti
Дата
Msg-id E1g7N0l-0000Vs-Dg@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/419cc8add5fb81331efbc7ea8862e08b981b7762

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(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Fix documentation of pgrowlocks using "lock_type" instead of"mo
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Set snprintf.c's maximum number of NL arguments to be 31.