From b20df972edf56c53a27d47839cdf58130bc6dfdc Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Tue, 2 Sep 2014 18:56:28 -0400 Subject: [PATCH] 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. --- src/t_string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t_string.c b/src/t_string.c index 2bf772a2..f0669381 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -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);