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

Commit0f4970d

Browse files
committed
Fix error case for CREATE ROLE ... IN ROLE.
CreateRole() was passing a Value node, not a RoleSpec node, for thenewly-created role name when adding the role as a member of existingroles for the IN ROLE syntax.This mistake went unnoticed because the node in question is used onlyfor error messages and is not accessed on non-error paths.In older pg versions (such as 9.5 where this was found), this resultsin an "unexpected node type" error in place of the real error. Thatnode type check was removed at some point, after which the code wouldaccidentally fail to fail on 64-bit platforms (on which accessing theValue node as if it were a RoleSpec would be mostly harmless) or givean "unexpected role type" error on 32-bit platforms.Fix the code to pass the correct node type, and add an lfirst_nodeassertion just in case.Per report on irc from user m1chelangelo.Backpatch all the way, because this error has been around for a longtime.
1 parentb31f9fd commit0f4970d

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

‎src/backend/commands/user.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,31 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
455455
/*
456456
* Add the new role to the specified existing roles.
457457
*/
458-
foreach(item,addroleto)
458+
if (addroleto)
459459
{
460-
RoleSpec*oldrole=lfirst(item);
461-
HeapTupleoldroletup=get_rolespec_tuple(oldrole);
462-
Oidoldroleid=HeapTupleGetOid(oldroletup);
463-
char*oldrolename=NameStr(((Form_pg_authid)GETSTRUCT(oldroletup))->rolname);
464-
465-
AddRoleMems(oldrolename,oldroleid,
466-
list_make1(makeString(stmt->role)),
467-
list_make1_oid(roleid),
468-
GetUserId(), false);
460+
RoleSpec*thisrole=makeNode(RoleSpec);
461+
List*thisrole_list=list_make1(thisrole);
462+
List*thisrole_oidlist=list_make1_oid(roleid);
463+
464+
thisrole->roletype=ROLESPEC_CSTRING;
465+
thisrole->rolename=stmt->role;
466+
thisrole->location=-1;
469467

470-
ReleaseSysCache(oldroletup);
468+
foreach(item,addroleto)
469+
{
470+
RoleSpec*oldrole=lfirst(item);
471+
HeapTupleoldroletup=get_rolespec_tuple(oldrole);
472+
Form_pg_authidoldroleform= (Form_pg_authid)GETSTRUCT(oldroletup);
473+
Oidoldroleid=HeapTupleGetOid(oldroletup);
474+
char*oldrolename=NameStr(oldroleform->rolname);
475+
476+
AddRoleMems(oldrolename,oldroleid,
477+
thisrole_list,
478+
thisrole_oidlist,
479+
GetUserId(), false);
480+
481+
ReleaseSysCache(oldroletup);
482+
}
471483
}
472484

473485
/*
@@ -1478,7 +1490,7 @@ AddRoleMems(const char *rolename, Oid roleid,
14781490

14791491
forboth(specitem,memberSpecs,iditem,memberIds)
14801492
{
1481-
RoleSpec*memberRole=lfirst(specitem);
1493+
RoleSpec*memberRole=lfirst_node(RoleSpec,specitem);
14821494
Oidmemberid=lfirst_oid(iditem);
14831495
HeapTupleauthmem_tuple;
14841496
HeapTupletuple;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp