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

Commit4e47b02

Browse files
committed
Reorder superuser check in pg_log_backend_memory_contexts()
The use of this function is limited to superusers and the code includesa hardcoded check for that. However, the code would look for the PGPROCentry to signal for the memory dump before checking if the user is asuperuser or not, which does not make sense if we know that an errorwill be returned. Note that the code would let one know if a processwas a PostgreSQL process or not even for non-authorized users, which isnot the case now, but this avoids taking ProcArrayLock that will mostlikely finish by being unnecessary.Thanks to Julien Rouhaud and Tom Lane for the discussion.Discussion:https://postgr.es/m/YLxw1uVGIAP5uMPl@paquier.xyz
1 parent3bb309b commit4e47b02

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

‎src/backend/utils/adt/mcxtfuncs.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,15 @@ Datum
175175
pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
176176
{
177177
intpid=PG_GETARG_INT32(0);
178-
PGPROC*proc=BackendPidGetProc(pid);
178+
PGPROC*proc;
179+
180+
/* Only allow superusers to log memory contexts. */
181+
if (!superuser())
182+
ereport(ERROR,
183+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
184+
errmsg("must be a superuser to log memory contexts")));
185+
186+
proc=BackendPidGetProc(pid);
179187

180188
/*
181189
* BackendPidGetProc returns NULL if the pid isn't valid; but by the time
@@ -197,12 +205,6 @@ pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
197205
PG_RETURN_BOOL(false);
198206
}
199207

200-
/* Only allow superusers to log memory contexts. */
201-
if (!superuser())
202-
ereport(ERROR,
203-
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
204-
errmsg("must be a superuser to log memory contexts")));
205-
206208
if (SendProcSignal(pid,PROCSIG_LOG_MEMORY_CONTEXT,proc->backendId)<0)
207209
{
208210
/* Again, just a warning to allow loops */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp