Skip to content

Commit bdfcd45

Browse files
committed
Fix formatting and import order
Signed-off-by: Jacob Murphy <jkmurphy@google.com>
1 parent 888f47b commit bdfcd45

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/acl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
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. */
681681
void 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);

tests/unit/acl.tcl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,16 +1493,16 @@ start_server [list overrides [list "dir" $server_path "aclfile" "user.acl"] tags
14931493
} else {
14941494
assert_equal [dict get $acl $field] $expected_val
14951495
}
1496-
1497-
# Verify with LIST for specific cases to ensure quoting in serialization
1498-
if {$username eq "keyquoter"} {
1499-
set acl_list [r ACL LIST]
1500-
assert_match {*"~key\\\"name"*} $acl_list
1501-
}
1502-
if {$username eq "chanquoter"} {
1503-
set acl_list [r ACL LIST]
1504-
assert_match {*"&chan\\\"name"*} $acl_list
1505-
}
1496+
1497+
# Verify with LIST for specific cases to ensure quoting in serialization
1498+
if {$username eq "keyquoter"} {
1499+
set acl_list [r ACL LIST]
1500+
assert_match {*"~key\\\"name"*} $acl_list
1501+
}
1502+
if {$username eq "chanquoter"} {
1503+
set acl_list [r ACL LIST]
1504+
assert_match {*"&chan\\\"name"*} $acl_list
1505+
}
15061506
}
15071507

15081508
# Clean up user for next iteration

0 commit comments

Comments
 (0)