Skip to content

Commit b62aa83

Browse files
committed
fmgr_security_definer had better do a PG_TRY to ensure the outer userid
is restored on error exit.
1 parent c8196c8 commit b62aa83

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/backend/utils/fmgr/fmgr.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.84 2004/09/13 01:44:46 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.85 2004/10/01 20:39:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -794,7 +794,7 @@ fmgr_security_definer(PG_FUNCTION_ARGS)
794794
{
795795
Datum result;
796796
FmgrInfo *save_flinfo;
797-
struct fmgr_security_definer_cache *fcache;
797+
struct fmgr_security_definer_cache * volatile fcache;
798798
AclId save_userid;
799799
HeapTuple tuple;
800800

@@ -821,14 +821,25 @@ fmgr_security_definer(PG_FUNCTION_ARGS)
821821
fcache = fcinfo->flinfo->fn_extra;
822822

823823
save_flinfo = fcinfo->flinfo;
824-
fcinfo->flinfo = &fcache->flinfo;
825-
826824
save_userid = GetUserId();
827-
SetUserId(fcache->userid);
828-
result = FunctionCallInvoke(fcinfo);
829-
SetUserId(save_userid);
825+
826+
PG_TRY();
827+
{
828+
fcinfo->flinfo = &fcache->flinfo;
829+
SetUserId(fcache->userid);
830+
831+
result = FunctionCallInvoke(fcinfo);
832+
}
833+
PG_CATCH();
834+
{
835+
fcinfo->flinfo = save_flinfo;
836+
SetUserId(save_userid);
837+
PG_RE_THROW();
838+
}
839+
PG_END_TRY();
830840

831841
fcinfo->flinfo = save_flinfo;
842+
SetUserId(save_userid);
832843

833844
return result;
834845
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy