From a57294b339c89b87ef8f74ae2b95794dc3cd9b1c Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 27 Aug 2013 13:00:06 +0200 Subject: [PATCH] Fix an hypothetical issue in processMultibulkBuffer(). --- src/networking.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/networking.c b/src/networking.c index 0de87053..ff3d951f 100644 --- a/src/networking.c +++ b/src/networking.c @@ -967,15 +967,19 @@ int processMultibulkBuffer(redisClient *c) { pos += newline-(c->querybuf+pos)+2; if (ll >= REDIS_MBULK_BIG_ARG) { + size_t qblen; + /* If we are going to read a large object from network * try to make it likely that it will start at c->querybuf * boundary so that we can optimize object creation * avoiding a large copy of data. */ sdsrange(c->querybuf,pos,-1); pos = 0; + qblen = sdslen(c->querybuf); /* Hint the sds library about the amount of bytes this string is * going to contain. */ - c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2-sdslen(c->querybuf)); + if (qblen < ll+2) + c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2-qblen); } c->bulklen = ll; }