Describe the bug
To reproduce
127.0.0.1:6379> set a 2
OK
127.0.0.1:6379> get a
"2"
The result seems right, however the content returned by server is wrong. When using strace
it's clear that the result is wrong. It should be
$1\r\n2\r\n
After reviewed code, I found the bug is introduced in git sha(a106198878f85b91de651dde74587768e81d4506)
the fix code is
diff --git a/src/networking.c b/src/networking.c
index e3d0d25e4..589b3ed24 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -1080,8 +1080,8 @@ void addReplyBulk(client *c, robj *obj) {
* to the output buffer. */
char buf[34];
size_t len = ll2string(buf,sizeof(buf),(long)obj->ptr);
- buf[len+1] = '\r';
- buf[len+2] = '\n';
+ buf[len] = '\r';
+ buf[len+1] = '\n';
_addReplyLongLongBulk(c, len);
_addReplyToBufferOrList(c,buf,len+2);
If I'm right, please let me to do a code fix pr.
It's just in unstable branch now.
Expected behavior
A description of what you expected to happen.
Additional information
Any additional information that is relevant to the problem.
Comment From: raffertyyu
Another question is why redis-cli is able to parse the wrong content correctly. I found this bug when I was debugging twemproxy.
Comment From: sundb
@raffertyyu good catch, feel free to make a PR to fix it.