From b7a4cfb4b3287b7644471c4892e993f68dabf8b3 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sun, 29 Jun 2014 12:32:06 +0200 Subject: [PATCH] Handle large getrange requests Previously the end was casted to a smaller type which resulted in a wrong check and failed with values larger than handled by unsigned. Closes #1847, #1844 --- src/t_string.c | 2 +- tests/unit/basic.tcl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/t_string.c b/src/t_string.c index 41e4b3b71023..397363c5cb41 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -255,7 +255,7 @@ void getrangeCommand(redisClient *c) { if (end < 0) end = strlen+end; if (start < 0) start = 0; if (end < 0) end = 0; - if ((unsigned)end >= strlen) end = strlen-1; + if ((size_t)end >= strlen) end = strlen-1; /* Precondition: end >= 0 && end < strlen, so the only condition where * nothing can be returned is: start > end. */ diff --git a/tests/unit/basic.tcl b/tests/unit/basic.tcl index 6f7fe292c4ba..2579cc9dccf7 100644 --- a/tests/unit/basic.tcl +++ b/tests/unit/basic.tcl @@ -769,4 +769,9 @@ start_server {tags {"basic"}} { r keys * r keys * } {dlskeriewrioeuwqoirueioqwrueoqwrueqw} + + test {GETRANGE with huge ranges, Github issue #1844} { + r set foo bar + r getrange foo 0 4294967297 + } {bar} }