mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Fix InitializeSessionUserId not to deference NULL rolename pointer.
Dmitriy Sarafannikov, reviewed by Michael Paquier and Haribabu Kommi, with a minor fix by me.
This commit is contained in:
@ -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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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",
|
||||||
|
Reference in New Issue
Block a user