Skip to content

Commit f475fe3

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 bca0f60 commit f475fe3

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
@@ -4095,7 +4095,8 @@ pg_foreign_data_wrapper_aclmask(Oid fdw_oid, Oid roleid,
40954095
tuple = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdw_oid));
40964096
if (!HeapTupleIsValid(tuple))
40974097
ereport(ERROR,
4098-
(errmsg("foreign-data wrapper with OID %u does not exist",
4098+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4099+
errmsg("foreign-data wrapper with OID %u does not exist",
40994100
fdw_oid)));
41004101
fdwForm = (Form_pg_foreign_data_wrapper) GETSTRUCT(tuple);
41014102

@@ -4156,7 +4157,8 @@ pg_foreign_server_aclmask(Oid srv_oid, Oid roleid,
41564157
tuple = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(srv_oid));
41574158
if (!HeapTupleIsValid(tuple))
41584159
ereport(ERROR,
4159-
(errmsg("foreign server with OID %u does not exist",
4160+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4161+
errmsg("foreign server with OID %u does not exist",
41604162
srv_oid)));
41614163
srvForm = (Form_pg_foreign_server) GETSTRUCT(tuple);
41624164

@@ -4215,27 +4217,30 @@ pg_type_aclmask(Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how)
42154217
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid));
42164218
if (!HeapTupleIsValid(tuple))
42174219
ereport(ERROR,
4218-
(errmsg("type with OID %u does not exist",
4220+
(errcode(ERRCODE_UNDEFINED_OBJECT),
4221+
errmsg("type with OID %u does not exist",
42194222
type_oid)));
42204223
typeForm = (Form_pg_type) GETSTRUCT(tuple);
42214224

4222-
/* "True" array types don't manage permissions of their own */
4223-
if (typeForm->typelem != 0 && typeForm->typlen == -1)
4225+
/*
4226+
* "True" array types don't manage permissions of their own; consult the
4227+
* element type instead.
4228+
*/
4229+
if (OidIsValid(typeForm->typelem) && typeForm->typlen == -1)
42244230
{
42254231
Oid elttype_oid = typeForm->typelem;
42264232

42274233
ReleaseSysCache(tuple);
42284234

42294235
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(elttype_oid));
4236+
/* this case is not a user-facing error, so elog not ereport */
42304237
if (!HeapTupleIsValid(tuple))
4231-
ereport(ERROR,
4232-
(errmsg("type with OID %u does not exist",
4233-
type_oid)));
4238+
elog(ERROR, "cache lookup failed for type %u", elttype_oid);
42344239
typeForm = (Form_pg_type) GETSTRUCT(tuple);
42354240
}
42364241

42374242
/*
4238-
* Normal case: get the type's ACL from pg_type
4243+
* Now get the type's owner and ACL from the tuple
42394244
*/
42404245
ownerId = typeForm->typowner;
42414246

0 commit comments

Comments
 (0)