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
572a9674
Commit
572a9674
authored
Jul 05, 2011
by
Pieter Noordhuis
Browse files
Move overflow check to s_integer_lf
parent
73b6930e
Changes
1
Show whitespace changes
Inline
Side-by-side
parser.c
View file @
572a9674
...
@@ -225,16 +225,6 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -225,16 +225,6 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
i64
.
ui64
+=
ch
-
'0'
;
i64
.
ui64
+=
ch
-
'0'
;
TRANSITION
(
integer_09
);
TRANSITION
(
integer_09
);
}
else
if
(
ch
==
'\r'
)
{
}
else
if
(
ch
==
'\r'
)
{
/* Check if the uint64_t can be safely casted to int64_t */
if
(
i64
.
neg
)
{
if
(
i64
.
ui64
>
((
uint64_t
)(
-
(
INT64_MIN
+
1
))
+
1
))
/* Overflow */
goto
error
;
i64
.
i64
=
-
i64
.
ui64
;
}
else
{
if
(
i64
.
ui64
>
INT64_MAX
)
/* Overflow */
goto
error
;
i64
.
i64
=
i64
.
ui64
;
}
TRANSITION
(
integer_lf
);
TRANSITION
(
integer_lf
);
}
}
...
@@ -248,6 +238,17 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -248,6 +238,17 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
goto
error
;
goto
error
;
}
}
/* Check if the uint64_t can be safely casted to int64_t */
if
(
i64
.
neg
)
{
if
(
i64
.
ui64
>
((
uint64_t
)(
-
(
INT64_MIN
+
1
))
+
1
))
/* Overflow */
goto
error
;
i64
.
i64
=
-
i64
.
ui64
;
}
else
{
if
(
i64
.
ui64
>
INT64_MAX
)
/* Overflow */
goto
error
;
i64
.
i64
=
i64
.
ui64
;
}
/* Protocol length can be set regardless of type */
/* Protocol length can be set regardless of type */
cur
->
plen
=
nread
-
cur
->
poff
+
1
;
/* include \n */
cur
->
plen
=
nread
-
cur
->
poff
+
1
;
/* include \n */
...
...
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