summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-24 15:46:05 +0100
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-11-24 15:46:05 +0100
commit257a9d40a9a8e7fdfe5325945d2ef10fa2fc6362 (patch)
treedd952d9e383a738033afe31674856356299973e2
parentd4058be7b0864a3c8862fb38a4567579aca7a8e9 (diff)
Set error on unexpected nesting of multi bulks
-rw-r--r--hiredis.c7
-rw-r--r--test.c11
2 files changed, 18 insertions, 0 deletions
diff --git a/hiredis.c b/hiredis.c
index 5888dd3..490b7ea 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -294,6 +294,13 @@ static int processMultiBulkItem(redisReader *r) {
long elements;
int root = 0;
+ /* Set error for nested multi bulks with depth > 1 */
+ if (r->ridx == 2) {
+ redisSetReplyReaderError(r,sdscatprintf(sdsempty(),
+ "No support for nested multi bulk replies with depth > 1"));
+ return -1;
+ }
+
if ((p = readLine(r,NULL)) != NULL) {
elements = strtol(p,NULL,10);
root = (r->ridx == 0);
diff --git a/test.c b/test.c
index beccd60..a6527f6 100644
--- a/test.c
+++ b/test.c
@@ -256,6 +256,17 @@ static void test_reply_reader() {
strcasecmp(err,"Protocol error, got \"@\" as reply type byte") == 0);
redisReplyReaderFree(reader);
+ test("Set error on nested multi bulks with depth > 1: ");
+ reader = redisReplyReaderCreate();
+ redisReplyReaderFeed(reader,(char*)"*1\r\n",4);
+ redisReplyReaderFeed(reader,(char*)"*1\r\n",4);
+ redisReplyReaderFeed(reader,(char*)"*1\r\n",4);
+ ret = redisReplyReaderGetReply(reader,NULL);
+ err = redisReplyReaderGetError(reader);
+ test_cond(ret == REDIS_ERR &&
+ strncasecmp(err,"No support for",14) == 0);
+ redisReplyReaderFree(reader);
+
test("Works with NULL functions for reply: ");
reader = redisReplyReaderCreate();
redisReplyReaderSetReplyObjectFunctions(reader,NULL);