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
hiredis
Commits
f2be7480
Unverified
Commit
f2be7480
authored
Dec 23, 2021
by
sundb
Committed by
GitHub
Dec 22, 2021
Browse files
Fix integer overflow when format command larger than 4GB (#1030)
parent
58aacdac
Changes
3
Hide whitespace changes
Inline
Side-by-side
async.c
View file @
f2be7480
...
...
@@ -862,7 +862,7 @@ int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata
int
redisAsyncCommandArgv
(
redisAsyncContext
*
ac
,
redisCallbackFn
*
fn
,
void
*
privdata
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
{
sds
cmd
;
int
len
;
long
long
len
;
int
status
;
len
=
redisFormatSdsCommandArgv
(
&
cmd
,
argc
,
argv
,
argvlen
);
if
(
len
<
0
)
...
...
hiredis.c
View file @
f2be7480
...
...
@@ -572,13 +572,12 @@ int redisFormatCommand(char **target, const char *format, ...) {
* lengths. If the latter is set to NULL, strlen will be used to compute the
* argument lengths.
*/
int
redisFormatSdsCommandArgv
(
sds
*
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
long
long
redisFormatSdsCommandArgv
(
sds
*
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
{
sds
cmd
,
aux
;
unsigned
long
long
totlen
;
unsigned
long
long
totlen
,
len
;
int
j
;
size_t
len
;
/* Abort on a NULL target */
if
(
target
==
NULL
)
...
...
@@ -609,7 +608,7 @@ int redisFormatSdsCommandArgv(sds *target, int argc, const char **argv,
cmd
=
sdscatfmt
(
cmd
,
"*%i
\r\n
"
,
argc
);
for
(
j
=
0
;
j
<
argc
;
j
++
)
{
len
=
argvlen
?
argvlen
[
j
]
:
strlen
(
argv
[
j
]);
cmd
=
sdscatfmt
(
cmd
,
"$%
u
\r\n
"
,
len
);
cmd
=
sdscatfmt
(
cmd
,
"$%
U
\r\n
"
,
len
);
cmd
=
sdscatlen
(
cmd
,
argv
[
j
],
len
);
cmd
=
sdscatlen
(
cmd
,
"
\r\n
"
,
sizeof
(
"
\r\n
"
)
-
1
);
}
...
...
@@ -629,11 +628,11 @@ void redisFreeSdsCommand(sds cmd) {
* lengths. If the latter is set to NULL, strlen will be used to compute the
* argument lengths.
*/
int
redisFormatCommandArgv
(
char
**
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
{
long
long
redisFormatCommandArgv
(
char
**
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
{
char
*
cmd
=
NULL
;
/* final command */
in
t
pos
;
/* position in final command */
size_t
len
;
int
totlen
,
j
;
size_
t
pos
;
/* position in final command */
size_t
len
,
totlen
;
int
j
;
/* Abort on a NULL target */
if
(
target
==
NULL
)
...
...
@@ -1129,7 +1128,7 @@ int redisAppendCommand(redisContext *c, const char *format, ...) {
int
redisAppendCommandArgv
(
redisContext
*
c
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
)
{
sds
cmd
;
int
len
;
long
long
len
;
len
=
redisFormatSdsCommandArgv
(
&
cmd
,
argc
,
argv
,
argvlen
);
if
(
len
==
-
1
)
{
...
...
hiredis.h
View file @
f2be7480
...
...
@@ -134,8 +134,8 @@ void freeReplyObject(void *reply);
/* Functions to format a command according to the protocol. */
int
redisvFormatCommand
(
char
**
target
,
const
char
*
format
,
va_list
ap
);
int
redisFormatCommand
(
char
**
target
,
const
char
*
format
,
...);
int
redisFormatCommandArgv
(
char
**
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
);
int
redisFormatSdsCommandArgv
(
sds
*
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
);
long
long
redisFormatCommandArgv
(
char
**
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
);
long
long
redisFormatSdsCommandArgv
(
sds
*
target
,
int
argc
,
const
char
**
argv
,
const
size_t
*
argvlen
);
void
redisFreeCommand
(
char
*
cmd
);
void
redisFreeSdsCommand
(
sds
cmd
);
...
...
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