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
e670ccff
Unverified
Commit
e670ccff
authored
Jun 18, 2018
by
Salvatore Sanfilippo
Committed by
GitHub
Jun 18, 2018
Browse files
Merge pull request #4857 from youjiali1995/fix-command-getkeys
Fix core dump when using some commands with wrong arguments.
parents
a0b27dae
10dedc25
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
e670ccff
...
@@ -1240,7 +1240,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu
...
@@ -1240,7 +1240,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu
num
=
atoi
(
argv
[
2
]
->
ptr
);
num
=
atoi
(
argv
[
2
]
->
ptr
);
/* Sanity check. Don't return any key if the command is going to
/* Sanity check. Don't return any key if the command is going to
* reply with syntax error. */
* reply with syntax error. */
if
(
num
>
(
argc
-
3
))
{
if
(
num
<
1
||
num
>
(
argc
-
3
))
{
*
numkeys
=
0
;
*
numkeys
=
0
;
return
NULL
;
return
NULL
;
}
}
...
@@ -1269,7 +1269,7 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
...
@@ -1269,7 +1269,7 @@ int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
num
=
atoi
(
argv
[
2
]
->
ptr
);
num
=
atoi
(
argv
[
2
]
->
ptr
);
/* Sanity check. Don't return any key if the command is going to
/* Sanity check. Don't return any key if the command is going to
* reply with syntax error. */
* reply with syntax error. */
if
(
num
>
(
argc
-
3
))
{
if
(
num
<=
0
||
num
>
(
argc
-
3
))
{
*
numkeys
=
0
;
*
numkeys
=
0
;
return
NULL
;
return
NULL
;
}
}
...
@@ -1414,7 +1414,7 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
...
@@ -1414,7 +1414,7 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
if
(
streams_pos
!=
-
1
)
num
=
argc
-
streams_pos
-
1
;
if
(
streams_pos
!=
-
1
)
num
=
argc
-
streams_pos
-
1
;
/* Syntax error. */
/* Syntax error. */
if
(
streams_pos
==
-
1
||
num
%
2
!=
0
)
{
if
(
streams_pos
==
-
1
||
num
==
0
||
num
%
2
!=
0
)
{
*
numkeys
=
0
;
*
numkeys
=
0
;
return
NULL
;
return
NULL
;
}
}
...
...
src/server.c
View file @
e670ccff
...
@@ -2854,7 +2854,10 @@ NULL
...
@@ -2854,7 +2854,10 @@ NULL
int
*
keys
,
numkeys
,
j
;
int
*
keys
,
numkeys
,
j
;
if
(
!
cmd
)
{
if
(
!
cmd
)
{
addReplyErrorFormat
(
c
,
"Invalid command specified"
);
addReplyError
(
c
,
"Invalid command specified"
);
return
;
}
else
if
(
cmd
->
getkeys_proc
==
NULL
&&
cmd
->
firstkey
==
0
)
{
addReplyError
(
c
,
"The command has no key arguments"
);
return
;
return
;
}
else
if
((
cmd
->
arity
>
0
&&
cmd
->
arity
!=
c
->
argc
-
2
)
||
}
else
if
((
cmd
->
arity
>
0
&&
cmd
->
arity
!=
c
->
argc
-
2
)
||
((
c
->
argc
-
2
)
<
-
cmd
->
arity
))
((
c
->
argc
-
2
)
<
-
cmd
->
arity
))
...
@@ -2864,9 +2867,13 @@ NULL
...
@@ -2864,9 +2867,13 @@ NULL
}
}
keys
=
getKeysFromCommand
(
cmd
,
c
->
argv
+
2
,
c
->
argc
-
2
,
&
numkeys
);
keys
=
getKeysFromCommand
(
cmd
,
c
->
argv
+
2
,
c
->
argc
-
2
,
&
numkeys
);
addReplyMultiBulkLen
(
c
,
numkeys
);
if
(
!
keys
)
{
for
(
j
=
0
;
j
<
numkeys
;
j
++
)
addReplyBulk
(
c
,
c
->
argv
[
keys
[
j
]
+
2
]);
addReplyError
(
c
,
"Invalid arguments specified for command"
);
getKeysFreeResult
(
keys
);
}
else
{
addReplyMultiBulkLen
(
c
,
numkeys
);
for
(
j
=
0
;
j
<
numkeys
;
j
++
)
addReplyBulk
(
c
,
c
->
argv
[
keys
[
j
]
+
2
]);
getKeysFreeResult
(
keys
);
}
}
else
{
}
else
{
addReplyErrorFormat
(
c
,
"Unknown subcommand or wrong number of arguments for '%s'. Try COMMAND HELP"
,
(
char
*
)
c
->
argv
[
1
]
->
ptr
);
addReplyErrorFormat
(
c
,
"Unknown subcommand or wrong number of arguments for '%s'. Try COMMAND HELP"
,
(
char
*
)
c
->
argv
[
1
]
->
ptr
);
}
}
...
...
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