Fix bug of invalid username/password when "SET ROLE role_name PASSWORD 'passwd'" is used in loop.

This commit is contained in:
syj 2020-12-30 11:58:34 +08:00 committed by zhaowenhao
parent 0f5b0f4bbf
commit c9edc3a053
3 changed files with 25 additions and 2 deletions

View File

@ -2338,7 +2338,8 @@ static int _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, Snapshot sn
ClearCreateStmtUUIDS((CreateStmt *)stmt);
}
if (IsA(stmt, CreateRoleStmt) || IsA(stmt, AlterRoleStmt)) {
if (IsA(stmt, CreateRoleStmt) || IsA(stmt, AlterRoleStmt) ||
(IsA(stmt, VariableSetStmt) && ((VariableSetStmt *)stmt)->kind == VAR_SET_ROLEPWD)) {
stmt = (Node *)copyObject(stmt);
}
@ -2374,7 +2375,8 @@ static int _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, Snapshot sn
res = SPI_OK_UTILITY;
}
if (IsA(stmt, CreateRoleStmt) || IsA(stmt, AlterRoleStmt)) {
if (IsA(stmt, CreateRoleStmt) || IsA(stmt, AlterRoleStmt) ||
(IsA(stmt, VariableSetStmt) && ((VariableSetStmt *)stmt)->kind == VAR_SET_ROLEPWD)) {
pfree_ext(stmt);
}
}

View File

@ -1,5 +1,15 @@
create role test_myrole001 with password "gauss@123";
create role test_myrole002 with sysadmin password "gauss@123";
-- test "SET ROLE role_name PASSWORD 'passwd'" in loop
BEGIN
FOR i in 1..5 LOOP
SET ROLE test_myrole001 PASSWORD 'gauss@123';
RESET ROLE;
SET ROLE test_myrole002 PASSWORD 'gauss@123';
RESET ROLE;
END LOOP;
END;
/
set role test_myrole001 password "gauss@123";
alter role test_myrole002 SET maintenance_work_mem = 100000;
ERROR: Permission denied.

View File

@ -1,6 +1,17 @@
create role test_myrole001 with password "gauss@123";
create role test_myrole002 with sysadmin password "gauss@123";
-- test "SET ROLE role_name PASSWORD 'passwd'" in loop
BEGIN
FOR i in 1..5 LOOP
SET ROLE test_myrole001 PASSWORD 'gauss@123';
RESET ROLE;
SET ROLE test_myrole002 PASSWORD 'gauss@123';
RESET ROLE;
END LOOP;
END;
/
set role test_myrole001 password "gauss@123";
alter role test_myrole002 SET maintenance_work_mem = 100000;
alter role test_myrole002 rename to temp_myrole;