Skip to content
Snippets Groups Projects
Commit 546cd0d7 authored by Robert Haas's avatar Robert Haas
Browse files

Fix InitializeSessionUserId not to deference NULL rolename pointer.

Dmitriy Sarafannikov, reviewed by Michael Paquier and Haribabu Kommi,
with a minor fix by me.
parent d78a7d9c
Branches
Tags
No related merge requests found
...@@ -474,6 +474,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid) ...@@ -474,6 +474,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
{ {
HeapTuple roleTup; HeapTuple roleTup;
Form_pg_authid rform; Form_pg_authid rform;
char *rname;
/* /*
* Don't do scans if we're bootstrapping, none of the system catalogs * Don't do scans if we're bootstrapping, none of the system catalogs
...@@ -485,16 +486,25 @@ InitializeSessionUserId(const char *rolename, Oid roleid) ...@@ -485,16 +486,25 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
AssertState(!OidIsValid(AuthenticatedUserId)); AssertState(!OidIsValid(AuthenticatedUserId));
if (rolename != NULL) if (rolename != NULL)
{
roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(rolename)); roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(rolename));
if (!HeapTupleIsValid(roleTup))
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("role \"%s\" does not exist", rolename)));
}
else else
{
roleTup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid)); roleTup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
if (!HeapTupleIsValid(roleTup)) if (!HeapTupleIsValid(roleTup))
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("role \"%s\" does not exist", rolename))); errmsg("role with OID %u does not exist", roleid)));
}
rform = (Form_pg_authid) GETSTRUCT(roleTup); rform = (Form_pg_authid) GETSTRUCT(roleTup);
roleid = HeapTupleGetOid(roleTup); roleid = HeapTupleGetOid(roleTup);
rname = NameStr(rform->rolname);
AuthenticatedUserId = roleid; AuthenticatedUserId = roleid;
AuthenticatedUserIsSuperuser = rform->rolsuper; AuthenticatedUserIsSuperuser = rform->rolsuper;
...@@ -520,7 +530,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid) ...@@ -520,7 +530,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("role \"%s\" is not permitted to log in", errmsg("role \"%s\" is not permitted to log in",
rolename))); rname)));
/* /*
* Check connection limit for this role. * Check connection limit for this role.
...@@ -538,11 +548,11 @@ InitializeSessionUserId(const char *rolename, Oid roleid) ...@@ -538,11 +548,11 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_TOO_MANY_CONNECTIONS), (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
errmsg("too many connections for role \"%s\"", errmsg("too many connections for role \"%s\"",
rolename))); rname)));
} }
/* Record username and superuser status as GUC settings too */ /* Record username and superuser status as GUC settings too */
SetConfigOption("session_authorization", rolename, SetConfigOption("session_authorization", rname,
PGC_BACKEND, PGC_S_OVERRIDE); PGC_BACKEND, PGC_S_OVERRIDE);
SetConfigOption("is_superuser", SetConfigOption("is_superuser",
AuthenticatedUserIsSuperuser ? "on" : "off", AuthenticatedUserIsSuperuser ? "on" : "off",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment