Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
8f745da1
Unverified
Commit
8f745da1
authored
Oct 21, 2021
by
guybe7
Committed by
GitHub
Oct 21, 2021
Browse files
Fix sentinel commands, ACL dictIter leak (#9661)
parent
8bf4c2e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
8f745da1
...
@@ -426,6 +426,7 @@ void ACLChangeCommandPerm(user *u, struct redisCommand *cmd, int allow) {
...
@@ -426,6 +426,7 @@ void ACLChangeCommandPerm(user *u, struct redisCommand *cmd, int allow) {
struct
redisCommand
*
sub
=
(
struct
redisCommand
*
)
dictGetVal
(
de
);
struct
redisCommand
*
sub
=
(
struct
redisCommand
*
)
dictGetVal
(
de
);
ACLSetUserCommandBit
(
u
,
sub
->
id
,
allow
);
ACLSetUserCommandBit
(
u
,
sub
->
id
,
allow
);
}
}
dictReleaseIterator
(
di
);
}
}
}
}
...
...
src/module.c
View file @
8f745da1
...
@@ -944,10 +944,10 @@ RedisModuleCommandProxy *moduleCreateCommandProxy(RedisModuleCtx *ctx, const cha
...
@@ -944,10 +944,10 @@ RedisModuleCommandProxy *moduleCreateCommandProxy(RedisModuleCtx *ctx, const cha
*
*
* Note that we use the Redis command table 'getkeys_proc' in order to
* Note that we use the Redis command table 'getkeys_proc' in order to
* pass a reference to the command proxy structure. */
* pass a reference to the command proxy structure. */
cp
=
z
m
alloc
(
sizeof
(
*
cp
));
cp
=
z
c
alloc
(
sizeof
(
*
cp
));
cp
->
module
=
ctx
->
module
;
cp
->
module
=
ctx
->
module
;
cp
->
func
=
cmdfunc
;
cp
->
func
=
cmdfunc
;
cp
->
rediscmd
=
z
m
alloc
(
sizeof
(
*
rediscmd
));
cp
->
rediscmd
=
z
c
alloc
(
sizeof
(
*
rediscmd
));
cp
->
rediscmd
->
name
=
cmdname
;
cp
->
rediscmd
->
name
=
cmdname
;
cp
->
rediscmd
->
proc
=
RedisModuleCommandDispatcher
;
cp
->
rediscmd
->
proc
=
RedisModuleCommandDispatcher
;
cp
->
rediscmd
->
flags
=
flags
|
CMD_MODULE
;
cp
->
rediscmd
->
flags
=
flags
|
CMD_MODULE
;
...
...
src/server.c
View file @
8f745da1
...
@@ -628,7 +628,7 @@ struct redisCommand sentinelSubcommands[] = {
...
@@ -628,7 +628,7 @@ struct redisCommand sentinelSubcommands[] = {
{
"config"
,
sentinelCommand
,
-
3
,
{
"config"
,
sentinelCommand
,
-
3
,
"admin only-sentinel"
},
"admin only-sentinel"
},
{
"debug"
,
sentinelCommand
,
2
,
{
"debug"
,
sentinelCommand
,
-
2
,
"admin only-sentinel"
},
"admin only-sentinel"
},
{
"get-master-addr-by-name"
,
sentinelCommand
,
3
,
{
"get-master-addr-by-name"
,
sentinelCommand
,
3
,
...
@@ -673,7 +673,7 @@ struct redisCommand sentinelSubcommands[] = {
...
@@ -673,7 +673,7 @@ struct redisCommand sentinelSubcommands[] = {
{
"sentinels"
,
sentinelCommand
,
3
,
{
"sentinels"
,
sentinelCommand
,
3
,
"admin only-sentinel"
},
"admin only-sentinel"
},
{
"set"
,
sentinelCommand
,
5
,
{
"set"
,
sentinelCommand
,
-
3
,
"admin only-sentinel"
},
"admin only-sentinel"
},
{
"simulate-failure"
,
sentinelCommand
,
3
,
{
"simulate-failure"
,
sentinelCommand
,
3
,
...
@@ -2027,7 +2027,7 @@ struct redisCommand redisCommandTable[] = {
...
@@ -2027,7 +2027,7 @@ struct redisCommand redisCommandTable[] = {
"read-only fast"
},
"read-only fast"
},
{
"acl"
,
NULL
,
-
2
,
{
"acl"
,
NULL
,
-
2
,
""
,
"
sentinel
"
,
.
subcommands
=
aclSubcommands
},
.
subcommands
=
aclSubcommands
},
{
"stralgo"
,
NULL
,
-
2
,
{
"stralgo"
,
NULL
,
-
2
,
...
@@ -4449,16 +4449,17 @@ void commandAddSubcommand(struct redisCommand *parent, struct redisCommand *subc
...
@@ -4449,16 +4449,17 @@ void commandAddSubcommand(struct redisCommand *parent, struct redisCommand *subc
serverAssert
(
dictAdd
(
parent
->
subcommands_dict
,
sdsnew
(
subcommand
->
name
),
subcommand
)
==
DICT_OK
);
serverAssert
(
dictAdd
(
parent
->
subcommands_dict
,
sdsnew
(
subcommand
->
name
),
subcommand
)
==
DICT_OK
);
}
}
/* Parse the flags string description 'strflags' and set them to the
/* Parse the flags string description 'strflags' and set them to the
* command 'c'. If the flags are all valid C_OK is returned, otherwise
* command 'c'. Abort on error. */
* C_ERR is returned (yet the recognized flags are set in the command). */
void
parseCommandFlags
(
struct
redisCommand
*
c
,
char
*
strflags
)
{
int
populateSingleCommand
(
struct
redisCommand
*
c
,
char
*
strflags
)
{
int
argc
;
int
argc
;
sds
*
argv
;
sds
*
argv
;
/* Split the line into arguments for processing. */
/* Split the line into arguments for processing. */
argv
=
sdssplitargs
(
strflags
,
&
argc
);
argv
=
sdssplitargs
(
strflags
,
&
argc
);
if
(
argv
==
NULL
)
return
C_ERR
;
if
(
argv
==
NULL
)
serverPanic
(
"Failed splitting strflags!"
);
for
(
int
j
=
0
;
j
<
argc
;
j
++
)
{
for
(
int
j
=
0
;
j
<
argc
;
j
++
)
{
char
*
flag
=
argv
[
j
];
char
*
flag
=
argv
[
j
];
...
@@ -4497,6 +4498,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4497,6 +4498,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
}
else
if
(
!
strcasecmp
(
flag
,
"sentinel"
))
{
}
else
if
(
!
strcasecmp
(
flag
,
"sentinel"
))
{
c
->
flags
|=
CMD_SENTINEL
;
c
->
flags
|=
CMD_SENTINEL
;
}
else
if
(
!
strcasecmp
(
flag
,
"only-sentinel"
))
{
}
else
if
(
!
strcasecmp
(
flag
,
"only-sentinel"
))
{
c
->
flags
|=
CMD_SENTINEL
;
/* Obviously it's s sentinel command */
c
->
flags
|=
CMD_ONLY_SENTINEL
;
c
->
flags
|=
CMD_ONLY_SENTINEL
;
}
else
{
}
else
{
/* Parse ACL categories here if the flag name starts with @. */
/* Parse ACL categories here if the flag name starts with @. */
...
@@ -4507,7 +4509,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4507,7 +4509,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
c
->
flags
|=
catflag
;
c
->
flags
|=
catflag
;
}
else
{
}
else
{
sdsfreesplitres
(
argv
,
argc
);
sdsfreesplitres
(
argv
,
argc
);
return
C_ERR
;
serverPanic
(
"Unsupported command flag %s"
,
flag
)
;
}
}
}
}
}
}
...
@@ -4515,8 +4517,11 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4515,8 +4517,11 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
if
(
!
(
c
->
flags
&
CMD_CATEGORY_FAST
))
c
->
flags
|=
CMD_CATEGORY_SLOW
;
if
(
!
(
c
->
flags
&
CMD_CATEGORY_FAST
))
c
->
flags
|=
CMD_CATEGORY_SLOW
;
sdsfreesplitres
(
argv
,
argc
);
sdsfreesplitres
(
argv
,
argc
);
}
/* Now handle the key arguments spec flags */
void
populateCommandStructure
(
struct
redisCommand
*
c
)
{
int
argc
;
sds
*
argv
;
/* Redis commands don't need more args than STATIC_KEY_SPECS_NUM (Number of keys
/* Redis commands don't need more args than STATIC_KEY_SPECS_NUM (Number of keys
* specs can be greater than STATIC_KEY_SPECS_NUM only for module commands) */
* specs can be greater than STATIC_KEY_SPECS_NUM only for module commands) */
...
@@ -4530,7 +4535,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4530,7 +4535,7 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
/* Split the line into arguments for processing. */
/* Split the line into arguments for processing. */
argv
=
sdssplitargs
(
c
->
key_specs
[
i
].
sflags
,
&
argc
);
argv
=
sdssplitargs
(
c
->
key_specs
[
i
].
sflags
,
&
argc
);
if
(
argv
==
NULL
)
if
(
argv
==
NULL
)
return
C_ERR
;
serverPanic
(
"Failed splitting key sflags!"
)
;
for
(
int
j
=
0
;
j
<
argc
;
j
++
)
{
for
(
int
j
=
0
;
j
<
argc
;
j
++
)
{
char
*
flag
=
argv
[
j
];
char
*
flag
=
argv
[
j
];
...
@@ -4540,6 +4545,8 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4540,6 +4545,8 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
c
->
key_specs
[
i
].
flags
|=
CMD_KEY_READ
;
c
->
key_specs
[
i
].
flags
|=
CMD_KEY_READ
;
}
else
if
(
!
strcasecmp
(
flag
,
"incomplete"
))
{
}
else
if
(
!
strcasecmp
(
flag
,
"incomplete"
))
{
c
->
key_specs
[
i
].
flags
|=
CMD_KEY_INCOMPLETE
;
c
->
key_specs
[
i
].
flags
|=
CMD_KEY_INCOMPLETE
;
}
else
{
serverPanic
(
"Unsupported key-arg flag %s"
,
flag
);
}
}
}
}
...
@@ -4552,6 +4559,9 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4552,6 +4559,9 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
/* Handle the "movablekeys" flag (must be done after populating all key specs). */
/* Handle the "movablekeys" flag (must be done after populating all key specs). */
populateCommandMovableKeys
(
c
);
populateCommandMovableKeys
(
c
);
/* Assign the ID used for ACL. */
c
->
id
=
ACLGetCommandID
(
c
->
name
);
/* Handle subcommands */
/* Handle subcommands */
if
(
c
->
subcommands
)
{
if
(
c
->
subcommands
)
{
for
(
int
j
=
0
;
c
->
subcommands
[
j
].
name
;
j
++
)
{
for
(
int
j
=
0
;
c
->
subcommands
[
j
].
name
;
j
++
)
{
...
@@ -4559,14 +4569,11 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
...
@@ -4559,14 +4569,11 @@ int populateSingleCommand(struct redisCommand *c, char *strflags) {
/* Translate the command string flags description into an actual
/* Translate the command string flags description into an actual
* set of flags. */
* set of flags. */
if
(
populateSingleCommand
(
sub
,
sub
->
sflags
)
==
C_ERR
)
parseCommandFlags
(
sub
,
sub
->
sflags
);
serverPanic
(
"Unsupported command flag or key spec flag"
);
populateCommandStructure
(
sub
);
commandAddSubcommand
(
c
,
sub
);
commandAddSubcommand
(
c
,
sub
);
}
}
}
}
return
C_OK
;
}
}
/* Populates the Redis Command Table starting from the hard coded list
/* Populates the Redis Command Table starting from the hard coded list
...
@@ -4577,6 +4584,11 @@ void populateCommandTable(void) {
...
@@ -4577,6 +4584,11 @@ void populateCommandTable(void) {
for
(
j
=
0
;
j
<
numcommands
;
j
++
)
{
for
(
j
=
0
;
j
<
numcommands
;
j
++
)
{
struct
redisCommand
*
c
=
redisCommandTable
+
j
;
struct
redisCommand
*
c
=
redisCommandTable
+
j
;
int
retval1
,
retval2
;
/* Translate the command string flags description into an actual
* set of flags. */
parseCommandFlags
(
c
,
c
->
sflags
);
if
(
!
(
c
->
flags
&
CMD_SENTINEL
)
&&
server
.
sentinel_mode
)
if
(
!
(
c
->
flags
&
CMD_SENTINEL
)
&&
server
.
sentinel_mode
)
continue
;
continue
;
...
@@ -4584,15 +4596,7 @@ void populateCommandTable(void) {
...
@@ -4584,15 +4596,7 @@ void populateCommandTable(void) {
if
(
c
->
flags
&
CMD_ONLY_SENTINEL
&&
!
server
.
sentinel_mode
)
if
(
c
->
flags
&
CMD_ONLY_SENTINEL
&&
!
server
.
sentinel_mode
)
continue
;
continue
;
int
retval1
,
retval2
;
populateCommandStructure
(
c
);
/* Assign the ID used for ACL. */
c
->
id
=
ACLGetCommandID
(
c
->
name
);
/* Translate the command string flags description into an actual
* set of flags. */
if
(
populateSingleCommand
(
c
,
c
->
sflags
)
==
C_ERR
)
serverPanic
(
"Unsupported command flag or key spec flag"
);
retval1
=
dictAdd
(
server
.
commands
,
sdsnew
(
c
->
name
),
c
);
retval1
=
dictAdd
(
server
.
commands
,
sdsnew
(
c
->
name
),
c
);
/* Populate an additional dictionary that will be unaffected
/* Populate an additional dictionary that will be unaffected
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment