summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMadelyn Olson <madelyneolson@gmail.com>2020-10-27 12:47:02 -0700
committerMadelyn Olson <34459052+madolson@users.noreply.github.com>2020-10-28 10:01:20 -0700
commitd310beb4170ebbc8985ae120ee301f9213d33e39 (patch)
treeb4532e09aafb6ad813ff9beaf65e3e54996fc2f9 /src
parent411bcf1a41d2758823d17e0864ef45e5f3948b7a (diff)
downloadredis-d310beb4170ebbc8985ae120ee301f9213d33e39.tar.gz
White space tweaks and skip categories already applied
Diffstat (limited to 'src')
-rw-r--r--src/acl.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/acl.c b/src/acl.c
index 6f28818a0..f0523b635 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -488,6 +488,12 @@ sds ACLDescribeUserCommandRules(user *u) {
* already applied. */
user tu = {0};
user *tempuser = &tu;
+
+ /* Keep track of the categories that have been applied, to prevent
+ * applying them twice. */
+ char applied[sizeof(ACLCommandCategories)/sizeof(ACLCommandCategories[0])];
+ memset(applied, 0, sizeof(applied));
+
memcpy(tempuser->allowed_commands,
u->allowed_commands,
sizeof(u->allowed_commands));
@@ -495,9 +501,10 @@ sds ACLDescribeUserCommandRules(user *u) {
int best = -1;
unsigned long mindiff = INT_MAX, maxsame = 0;
for (int j = 0; ACLCommandCategories[j].flag != 0; j++) {
+ if (applied[j]) continue;
+
unsigned long on, off, diff, same;
ACLCountCategoryBitsForUser(tempuser,&on,&off,ACLCommandCategories[j].name);
-
/* Check if the current category is the best this loop:
* * It has more commands in common with the user than commands
* that are different.
@@ -509,7 +516,8 @@ sds ACLDescribeUserCommandRules(user *u) {
diff = additive ? off : on;
same = additive ? on : off;
if (same > diff &&
- ((diff < mindiff) || (diff == mindiff && same > maxsame))) {
+ ((diff < mindiff) || (diff == mindiff && same > maxsame)))
+ {
best = j;
mindiff = diff;
maxsame = same;
@@ -531,8 +539,9 @@ sds ACLDescribeUserCommandRules(user *u) {
rules = sdscatlen(rules," ",1);
sdsfree(op);
sdsfree(invop);
- }
+ applied[best] = 1;
+ }
/* Fix the final ACLs with single commands differences. */
dictIterator *di = dictGetIterator(server.orig_commands);