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
7c96b467
Commit
7c96b467
authored
Feb 21, 2012
by
antirez
Browse files
Fixed undefined behavior in *INCR style functions overflow detection. Sorry clang!
parent
fe7be460
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/t_hash.c
View file @
7c96b467
...
...
@@ -337,11 +337,12 @@ void hincrbyCommand(redisClient *c) {
}
oldvalue
=
value
;
value
+=
incr
;
if
(
(
incr
<
0
&&
value
>
oldvalue
)
||
(
incr
>
0
&&
value
<
oldvalue
))
{
if
((
incr
<
0
&&
oldvalue
<
0
&&
incr
<
(
LLONG_MIN
-
oldvalue
))
||
(
incr
>
0
&&
oldvalue
>
0
&&
incr
>
(
LLONG_MAX
-
oldvalue
))
)
{
addReplyError
(
c
,
"increment or decrement would overflow"
);
return
;
}
value
+=
incr
;
new
=
createStringObjectFromLongLong
(
value
);
hashTypeTryObjectEncoding
(
o
,
&
c
->
argv
[
2
],
NULL
);
hashTypeSet
(
o
,
c
->
argv
[
2
],
new
);
...
...
src/t_string.c
View file @
7c96b467
...
...
@@ -344,11 +344,12 @@ void incrDecrCommand(redisClient *c, long long incr) {
if
(
getLongLongFromObjectOrReply
(
c
,
o
,
&
value
,
NULL
)
!=
REDIS_OK
)
return
;
oldvalue
=
value
;
value
+=
incr
;
if
(
(
incr
<
0
&&
value
>
oldvalue
)
||
(
incr
>
0
&&
value
<
oldvalue
))
{
if
((
incr
<
0
&&
oldvalue
<
0
&&
incr
<
(
LLONG_MIN
-
oldvalue
))
||
(
incr
>
0
&&
oldvalue
>
0
&&
incr
>
(
LLONG_MAX
-
oldvalue
))
)
{
addReplyError
(
c
,
"increment or decrement would overflow"
);
return
;
}
value
+=
incr
;
new
=
createStringObjectFromLongLong
(
value
);
if
(
o
)
dbOverwrite
(
c
->
db
,
c
->
argv
[
1
],
new
);
...
...
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