File CVE-2023-41053.patch of Package redis7.35902

From 9e505e6cd842338424e05883521ca1fb7d0f47f6 Mon Sep 17 00:00:00 2001
From: "bodong.ybd" <bodong.ybd@alibaba-inc.com>
Date: Thu, 31 Aug 2023 03:00:02 +0800
Subject: [PATCH] Fix sort_ro get-keys function return wrong key number
 (#12522)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before:
```
127.0.0.1:6379> command getkeys sort_ro key
(empty array)
127.0.0.1:6379>
```
After:
```
127.0.0.1:6379> command getkeys sort_ro key
1) "key"
127.0.0.1:6379>
```

(cherry picked from commit b59f53efb31b36d0a307809f5d33bf66d66a4447)
---
 src/db.c            | 3 ++-
 tests/unit/sort.tcl | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/db.c b/src/db.c
index 7b34fcb4700a..a7cb4dbd3713 100644
--- a/src/db.c
+++ b/src/db.c
@@ -2294,7 +2294,8 @@ int sortROGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult
     keys = getKeysPrepareResult(result, 1);
     keys[0].pos = 1; /* <sort-key> is always present. */
     keys[0].flags = CMD_KEY_RO | CMD_KEY_ACCESS;
-    return 1;
+    result->numkeys = 1;
+    return result->numkeys;
 }
 
 /* Helper function to extract keys from the SORT command.
diff --git a/tests/unit/sort.tcl b/tests/unit/sort.tcl
index 7ef4fb1e5da5..d4927cf84bbd 100644
--- a/tests/unit/sort.tcl
+++ b/tests/unit/sort.tcl
@@ -109,6 +109,10 @@ start_server {
     test "SORT extracts STORE correctly" {
         r command getkeys sort abc store def
     } {abc def}
+    
+    test "SORT_RO get keys" {
+        r command getkeys sort_ro abc
+    } {abc}
 
     test "SORT extracts multiple STORE correctly" {
         r command getkeys sort abc store invalid store stillbad store def
openSUSE Build Service is sponsored by