]> git.saurik.com Git - redis.git/blobdiff - src/networking.c
Prevent clients from making too large multibulk requests
[redis.git] / src / networking.c
index cc4c9341d6b2ad6d4bb2323e1a8c6a59ffe7ec7e..46d49bf6c5639febe72696852f06afe5cff56b0b 100644 (file)
@@ -724,6 +724,10 @@ int processMultibulkBuffer(redisClient *c) {
         if (c->multibulklen <= 0) {
             c->querybuf = sdsrange(c->querybuf,pos,-1);
             return REDIS_OK;
+        } else if (c->multibulklen > 1024*1024) {
+            addReplyError(c,"Protocol error: invalid multibulk length");
+            setProtocolError(c,pos);
+            return REDIS_ERR;
         }
 
         /* Setup argv array on client structure */
@@ -820,9 +824,13 @@ void processInputBuffer(redisClient *c) {
         }
 
         /* Multibulk processing could see a <= 0 length. */
-        if (c->argc > 0)
-            processCommand(c);
-        resetClient(c);
+        if (c->argc == 0) {
+            resetClient(c);
+        } else {
+            /* Only reset the client when the command was executed. */
+            if (processCommand(c) == REDIS_OK)
+                resetClient(c);
+        }
     }
 }