summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-08-27 11:56:47 +0200
committerantirez <antirez@gmail.com>2013-08-27 12:30:42 +0200
commit79a1d335c85be3b66a89962f71e830df7eea8c35 (patch)
tree8142570b9821fcc5629f621d9e0e7f5c0ab56e8a
parent0f32c37fc92b5a69cd9940c0dd1df9da6921a644 (diff)
downloadredis-79a1d335c85be3b66a89962f71e830df7eea8c35.tar.gz
tryObjectEncoding(): don't call stringl2() for too big strings.
We are sure that a string that is longer than 21 chars cannot be represented by a 64 bit signed integer, as -(2^64) is 21 chars: strlen(-18446744073709551616) => 21
-rw-r--r--src/object.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/object.c b/src/object.c
index 5202c0c55..1c9c37e80 100644
--- a/src/object.c
+++ b/src/object.c
@@ -278,6 +278,7 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) {
robj *tryObjectEncoding(robj *o) {
long value;
sds s = o->ptr;
+ size_t len;
if (o->encoding != REDIS_ENCODING_RAW)
return o; /* Already encoded */
@@ -291,7 +292,8 @@ robj *tryObjectEncoding(robj *o) {
redisAssertWithInfo(NULL,o,o->type == REDIS_STRING);
/* Check if we can represent this string as a long integer */
- if (!string2l(s,sdslen(s),&value)) return o;
+ len = sdslen(s);
+ if (len > 21 || !string2l(s,len,&value)) return o;
/* Ok, this object can be encoded...
*