Commit 572a9674 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Move overflow check to s_integer_lf

parent 73b6930e
...@@ -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 */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment