Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6463ea

Browse files
committed
Downgrade error in object_aclmask_ext() to internal
The "does not exist" error in object_aclmask_ext() was written asereport(), suggesting that it is user-facing. This is problematic:get_object_class_descr() is meant to be for internal errors only anddoes not support translation.For the has_xxx_privilege functions, the error has not beenuser-facing since commit403ac22. The remaining users arepg_database_size() and pg_tablespace_size(). The call stack here ispretty deep and this dependency is not obvious. Here we can put in anexplicit existence check with a bespoke error message early in thefunction.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 parentde9037d commitb6463ea

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 2 additions & 8 deletions
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
return0;
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ pg_database_size_oid(PG_FUNCTION_ARGS)
170170
OiddbOid=PG_GETARG_OID(0);
171171
int64size;
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
OidtblspcOid=PG_GETARG_OID(0);
275284
int64size;
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)

[8]ページ先頭

©2009-2025 Movatter.jp