diff options
author | ZhaolongLi <0x4f4f4f4f@gmail.com> | 2021-06-30 21:55:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 16:55:09 +0300 |
commit | 6476c8e856f790bef24eacd62c10c2df54e33f14 (patch) | |
tree | 1a1c55e7f0577dd3ea379a5999e9919fb50cc2c4 | |
parent | 74fe15b3602ed7c003b5c53e45e31f7aa6d4a86f (diff) | |
download | redis-6476c8e856f790bef24eacd62c10c2df54e33f14.tar.gz |
Fix range issues in default value of LIMIT argument to XADD and XTRIM (#9147)
This seems to be an unimportant bug that was accidentally generated. If the user does not specify limit in streamParseAddOrTrimArgsOrReply, the initial value of args->limit is 100 * server.stream_node_max_entries, which may lead to out of bounds, and then the default function of limit in xadd becomes invalid (this failure occurs in streamTrim).
Additionally, provide sane default for args->limit in case stream_node_max_entries is set to 0.
Co-authored-by: lizhaolong.lzl <lizhaolong.lzl@B-54MPMD6R-0221.local>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: guybe7 <guy.benoish@redislabs.com>
-rw-r--r-- | src/t_stream.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/t_stream.c b/src/t_stream.c index ceb4950e1..90dfb3307 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -982,11 +982,15 @@ static int streamParseAddOrTrimArgsOrReply(client *c, streamAddTrimArgs *args, i } } else { /* User didn't provide LIMIT, we must set it. */ - if (args->approx_trim) { - /* In order to prevent from trimming to do too much work and cause - * latency spikes we limit the amount of work it can do */ + /* In order to prevent from trimming to do too much work and + * cause latency spikes we limit the amount of work it can do. + * We have to cap args->limit from both sides in case + * stream_node_max_entries is 0 or too big (could cause overflow) + */ args->limit = 100 * server.stream_node_max_entries; /* Maximum 100 rax nodes. */ + if (args->limit <= 0) args->limit = 10000; + if (args->limit > 1000000) args->limit = 1000000; } else { /* No LIMIT for exact trimming */ args->limit = 0; |