Skip to content

[BUG] wrong content returned by redis-server #13709

@raffertyyu

Description

@raffertyyu

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
image
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(a106198)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions