Skip to content

Commit b6463ea

Browse files
committed
Downgrade error in object_aclmask_ext() to internal
The "does not exist" error in object_aclmask_ext() was written as ereport(), suggesting that it is user-facing. This is problematic: get_object_class_descr() is meant to be for internal errors only and does not support translation. For the has_xxx_privilege functions, the error has not been user-facing since commit 403ac22. The remaining users are pg_database_size() and pg_tablespace_size(). The call stack here is pretty deep and this dependency is not obvious. Here we can put in an explicit existence check with a bespoke error message early in the function. Then we can downgrade the error in object_aclmask_ext() to a normal "cache lookup failed" internal error. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://www.postgresql.org/message-id/flat/da2f8942-be6d-48d0-ac1c-a053370a6b1f@eisentraut.org
1 parent de9037d commit b6463ea

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/backend/catalog/aclchk.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -3004,10 +3004,6 @@ pg_aclmask(ObjectType objtype, Oid object_oid, AttrNumber attnum, Oid roleid,
30043004
* Exported routines for examining a user's privileges for various objects
30053005
*
30063006
* See aclmask() for a description of the common API for these functions.
3007-
*
3008-
* Note: we give lookup failure the full ereport treatment because the
3009-
* has_xxx_privilege() family of functions allow users to pass any random
3010-
* OID to these functions.
30113007
* ****************************************************************
30123008
*/
30133009

@@ -3074,10 +3070,8 @@ object_aclmask_ext(Oid classid, Oid objectid, Oid roleid,
30743070
return 0;
30753071
}
30763072
else
3077-
ereport(ERROR,
3078-
(errcode(ERRCODE_UNDEFINED_OBJECT),
3079-
errmsg("%s with OID %u does not exist",
3080-
get_object_class_descr(classid), objectid)));
3073+
elog(ERROR, "cache lookup failed for %s %u",
3074+
get_object_class_descr(classid), objectid);
30813075
}
30823076

30833077
ownerId = DatumGetObjectId(SysCacheGetAttrNotNull(cacheid,

src/backend/utils/adt/dbsize.c

+18
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ pg_database_size_oid(PG_FUNCTION_ARGS)
170170
Oid dbOid = PG_GETARG_OID(0);
171171
int64 size;
172172

173+
/*
174+
* Not needed for correctness, but avoid non-user-facing error message
175+
* later if the database doesn't exist.
176+
*/
177+
if (!SearchSysCacheExists1(DATABASEOID, ObjectIdGetDatum(dbOid)))
178+
ereport(ERROR,
179+
errcode(ERRCODE_UNDEFINED_OBJECT),
180+
errmsg("database with OID %u does not exist", dbOid));
181+
173182
size = calculate_database_size(dbOid);
174183

175184
if (size == 0)
@@ -274,6 +283,15 @@ pg_tablespace_size_oid(PG_FUNCTION_ARGS)
274283
Oid tblspcOid = PG_GETARG_OID(0);
275284
int64 size;
276285

286+
/*
287+
* Not needed for correctness, but avoid non-user-facing error message
288+
* later if the tablespace doesn't exist.
289+
*/
290+
if (!SearchSysCacheExists1(TABLESPACEOID, ObjectIdGetDatum(tblspcOid)))
291+
ereport(ERROR,
292+
errcode(ERRCODE_UNDEFINED_OBJECT),
293+
errmsg("tablespace with OID %u does not exist", tblspcOid));
294+
277295
size = calculate_tablespace_size(tblspcOid);
278296

279297
if (size < 0)

0 commit comments

Comments
 (0)