Skip to content

Commit f8d0a82

Browse files
committed
Avoid an Assert failure if OuterUserId hasn't been set yet during
AbortTransaction. This can happen if a backend's InitPostgres transaction fails (eg, because the given username is invalid). Per Alvaro.
1 parent 63f850c commit f8d0a82

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/backend/access/transam/xact.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.212 2005/08/08 19:17:22 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.213 2005/08/17 22:14:33 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -1877,16 +1877,16 @@ AbortTransaction(void)
18771877

18781878
/*
18791879
* Reset user id which might have been changed transiently. We cannot
1880-
* use s->currentUser, but must get the session outer-level userid from
1881-
* miscinit.c.
1880+
* use s->currentUser, since it may not be set yet; instead rely on
1881+
* internal state of miscinit.c.
18821882
*
18831883
* (Note: it is not necessary to restore session authorization here
18841884
* because that can only be changed via GUC, and GUC will take care of
18851885
* rolling it back if need be. However, an error within a SECURITY
18861886
* DEFINER function could send control here with the wrong current
18871887
* userid.)
18881888
*/
1889-
SetUserId(GetOuterUserId());
1889+
AtAbort_UserId();
18901890

18911891
/*
18921892
* do abort processing

src/backend/utils/init/miscinit.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.148 2005/07/31 17:19:19 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.149 2005/08/17 22:14:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -286,7 +286,7 @@ make_absolute_path(const char *path)
286286
* OuterUserId is the current user ID in effect at the "outer level" (outside
287287
* any transaction or function). This is initially the same as SessionUserId,
288288
* but can be changed by SET ROLE to any role that SessionUserId is a
289-
* member of. We store this mainly so that AbortTransaction knows what to
289+
* member of. We store this mainly so that AtAbort_UserId knows what to
290290
* reset CurrentUserId to.
291291
*
292292
* CurrentUserId is the current effective user ID; this is the one to use
@@ -496,6 +496,21 @@ InitializeSessionUserIdStandalone(void)
496496
}
497497

498498

499+
/*
500+
* Reset effective userid during AbortTransaction
501+
*
502+
* This is essentially SetUserId(GetOuterUserId()), but without the Asserts.
503+
* The reason is that if a backend's InitPostgres transaction fails (eg,
504+
* because an invalid user name was given), we have to be able to get through
505+
* AbortTransaction without asserting.
506+
*/
507+
void
508+
AtAbort_UserId(void)
509+
{
510+
CurrentUserId = OuterUserId;
511+
}
512+
513+
499514
/*
500515
* Change session auth ID while running
501516
*

src/include/miscadmin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.178 2005/07/25 22:12:34 tgl Exp $
16+
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.179 2005/08/17 22:14:34 tgl Exp $
1717
*
1818
* NOTES
1919
* some of the information in this file should be moved to other files.
@@ -235,6 +235,7 @@ extern Oid GetOuterUserId(void);
235235
extern Oid GetSessionUserId(void);
236236
extern void InitializeSessionUserId(const char *rolename);
237237
extern void InitializeSessionUserIdStandalone(void);
238+
extern void AtAbort_UserId(void);
238239
extern void SetSessionAuthorization(Oid userid, bool is_superuser);
239240
extern Oid GetCurrentRoleId(void);
240241
extern void SetCurrentRoleId(Oid roleid, bool is_superuser);

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