2727 * POSSIBILITY OF SUCH DAMAGE.
2828 */
2929
30- #include "sds.h"
3130#include "server.h"
31+ #include "sds.h"
3232#include "sha256.h"
3333#include "module.h"
3434#include "intset.h"
@@ -676,7 +676,7 @@ static void ACLSetSelectorCommandBitsForCategory(hashtable *commands, aclSelecto
676676}
677677
678678/* This function is responsible for recomputing the command bits for all selectors of the existing users.
679- * It uses the 'command_rules', a string representation of the ordered categories and commands,
679+ * It uses the 'command_rules', a list of the ordered categories and commands,
680680 * to recompute the command bits. */
681681void ACLRecomputeCommandBitsFromCommandRulesAllUsers (void ) {
682682 raxIterator ri ;
@@ -689,6 +689,10 @@ void ACLRecomputeCommandBitsFromCommandRulesAllUsers(void) {
689689 listRewind (u -> selectors , & li );
690690 while ((ln = listNext (& li ))) {
691691 aclSelector * selector = (aclSelector * )listNodeValue (ln );
692+ /* Duplicate the rules list before resetting the selector, as
693+ * ACLSetSelector will clear selector->command_rules. */
694+ list * rules_copy = listDup (selector -> command_rules );
695+
692696 /* Checking selector's permissions for all commands to start with a clean state. */
693697 if (ACLSelectorCanExecuteFutureCommands (selector )) {
694698 int res = ACLSetSelector (selector , "+@all" , -1 );
@@ -698,15 +702,16 @@ void ACLRecomputeCommandBitsFromCommandRulesAllUsers(void) {
698702 serverAssert (res == C_OK );
699703 }
700704
701- /* Apply all of the commands and categories to this selector. */
705+ /* Apply all of the commands and categories to this selector from the copy . */
702706 listIter sli ;
703707 listNode * sln ;
704- listRewind (selector -> command_rules , & sli );
708+ listRewind (rules_copy , & sli );
705709 while ((sln = listNext (& sli ))) {
706710 sds rule = listNodeValue (sln );
707711 int res = ACLSetSelector (selector , rule , sdslen (rule ));
708712 serverAssert (res == C_OK );
709713 }
714+ listRelease (rules_copy );
710715 }
711716 }
712717 raxStop (& ri );
0 commit comments