summaryrefslogtreecommitdiff
path: root/src/t_set.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2023-01-16 13:51:18 +0200
committerGitHub <noreply@github.com>2023-01-16 13:51:18 +0200
commitb4123663c31aaf1e97f4dbd630cbd7b8d0e91e31 (patch)
treee4f5e77cfd93c76cbf7c80bfeb11bc4ac58faea6 /src/t_set.c
parent16f408b1a0121cacd44cbf8aee275d69dc627f02 (diff)
downloadredis-b4123663c31aaf1e97f4dbd630cbd7b8d0e91e31.tar.gz
Obuf limit, exit during loop in *RAND* commands and KEYS (#11676)
Related to the hang reported in #11671 Currently, redis can disconnect a client due to reaching output buffer limit, it'll also avoid feeding that output buffer with more data, but it will keep running the loop in the command (despite the client already being marked for disconnection) This PR is an attempt to mitigate the problem, specifically for commands that are easy to abuse, specifically: KEYS, HRANDFIELD, SRANDMEMBER, ZRANDMEMBER. The RAND family of commands can take a negative COUNT argument (which is not bound to the number of elements in the key), so it's enough to create a key with one field, and then these commands can be used to hang redis. For KEYS the caller can use the existing keyspace in redis (if big enough).
Diffstat (limited to 'src/t_set.c')
-rw-r--r--src/t_set.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/t_set.c b/src/t_set.c
index 6a4840676..6d8023f31 100644
--- a/src/t_set.c
+++ b/src/t_set.c
@@ -1028,6 +1028,8 @@ void srandmemberWithCountCommand(client *c) {
else
addReplyBulkLongLong(c, entries[i].lval);
}
+ if (c->flags & CLIENT_CLOSE_ASAP)
+ break;
}
zfree(entries);
return;
@@ -1040,6 +1042,8 @@ void srandmemberWithCountCommand(client *c) {
} else {
addReplyBulkCBuffer(c, str, len);
}
+ if (c->flags & CLIENT_CLOSE_ASAP)
+ break;
}
return;
}