Return empty string if GETRANGE of empty string

Previously, GETRANGE of a key containing nothing ("")
would allocate a large (size_t)-1 return value causing
crashes on 32bit builds when it tried to allocate the
4 GB return string.
This commit is contained in:
Matt Stancliff 2014-09-02 18:56:28 -04:00
parent f0e306f4a0
commit b20df972ed

View File

@ -259,7 +259,7 @@ void getrangeCommand(redisClient *c) {
/* Precondition: end >= 0 && end < strlen, so the only condition where
* nothing can be returned is: start > end. */
if (start > end) {
if (start > end || strlen == 0) {
addReply(c,shared.emptybulk);
} else {
addReplyBulkCBuffer(c,(char*)str+start,end-start+1);