Skip to content

Commit 783cb6e

Browse files
committed
Fix multiple minor infelicities in aclchk.c error reports.
pg_type_aclmask reported the wrong type's OID when complaining that it could not find a type's typelem. It also failed to provide a suitable errcode when the initially given OID doesn't exist (which is a user-facing error, since that OID can be user-specified). pg_foreign_data_wrapper_aclmask and pg_foreign_server_aclmask likewise lacked errcode specifications. Trivial cosmetic adjustments too. The wrong-type-OID problem was reported by Petru-Florin Mihancea in bug #14186; the other issues noted by me while reading the code. These errors all seem to be aboriginal in the respective routines, so back-patch as necessary. Report: <20160613163159.5798.52928@wrigleys.postgresql.org>
1 parent 89d5351 commit 783cb6e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/backend/catalog/aclchk.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,7 +4108,8 @@ pg_foreign_data_wrapper_aclmask(Oid fdw_oid, Oid roleid,
41084108
tuple = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdw_oid));
41094109
if (!HeapTupleIsValid(tuple))
41104110
ereport(ERROR,
4111-
(errmsg("foreign-data wrapper with OID %u does not exist",
4111+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4112+
errmsg("foreign-data wrapper with OID %u does not exist",
41124113
fdw_oid)));
41134114
fdwForm = (Form_pg_foreign_data_wrapper) GETSTRUCT(tuple);
41144115

@@ -4169,7 +4170,8 @@ pg_foreign_server_aclmask(Oid srv_oid, Oid roleid,
41694170
tuple = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(srv_oid));
41704171
if (!HeapTupleIsValid(tuple))
41714172
ereport(ERROR,
4172-
(errmsg("foreign server with OID %u does not exist",
4173+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4174+
errmsg("foreign server with OID %u does not exist",
41734175
srv_oid)));
41744176
srvForm = (Form_pg_foreign_server) GETSTRUCT(tuple);
41754177

@@ -4228,27 +4230,30 @@ pg_type_aclmask(Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how)
42284230
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid));
42294231
if (!HeapTupleIsValid(tuple))
42304232
ereport(ERROR,
4231-
(errmsg("type with OID %u does not exist",
4233+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4234+
errmsg("type with OID %u does not exist",
42324235
type_oid)));
42334236
typeForm = (Form_pg_type) GETSTRUCT(tuple);
42344237

4235-
/* "True" array types don't manage permissions of their own */
4236-
if (typeForm->typelem != 0 && typeForm->typlen == -1)
4238+
/*
4239+
* "True" array types don't manage permissions of their own; consult the
4240+
* element type instead.
4241+
*/
4242+
if (OidIsValid(typeForm->typelem) && typeForm->typlen == -1)
42374243
{
42384244
Oid elttype_oid = typeForm->typelem;
42394245

42404246
ReleaseSysCache(tuple);
42414247

42424248
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(elttype_oid));
4249+
/* this case is not a user-facing error, so elog not ereport */
42434250
if (!HeapTupleIsValid(tuple))
4244-
ereport(ERROR,
4245-
(errmsg("type with OID %u does not exist",
4246-
type_oid)));
4251+
elog(ERROR, "cache lookup failed for type %u", elttype_oid);
42474252
typeForm = (Form_pg_type) GETSTRUCT(tuple);
42484253
}
42494254

42504255
/*
4251-
* Normal case: get the type's ACL from pg_type
4256+
* Now get the type's owner and ACL from the tuple
42524257
*/
42534258
ownerId = typeForm->typowner;
42544259

0 commit comments

Comments
 (0)