From c275010fffe03ac83c5636ed464d7e57f7d96005 Mon Sep 17 00:00:00 2001 From: Madelyn Olson <34459052+madolson@users.noreply.github.com> Date: Mon, 24 Jan 2022 22:08:57 -0800 Subject: [PATCH] Correctly handle minimum arity checks in scripts (#10171) Correctly handle variable arity checks in scripts --- src/script.c | 2 +- tests/unit/scripting.tcl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/script.c b/src/script.c index ded531e14..14a64b961 100644 --- a/src/script.c +++ b/src/script.c @@ -284,7 +284,7 @@ void scriptKill(client *c, int is_eval) { } static int scriptVerifyCommandArity(struct redisCommand *cmd, int argc, sds *err) { - if (!cmd || ((cmd->arity > 0 && cmd->arity != argc) || (argc < cmd->arity))) { + if (!cmd || ((cmd->arity > 0 && cmd->arity != argc) || (argc < -cmd->arity))) { if (cmd) *err = sdsnew("Wrong number of args calling Redis command from script"); else diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 9e1246355..f16555350 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -598,6 +598,11 @@ start_server {tags {"scripting"}} { set e } {ERR Number of keys can't be negative} + test {Scripts can handle commands with incorrect arity} { + assert_error "*Wrong number of args calling Redis command from script" {run_script "redis.call('set','invalid')" 0} + assert_error "*Wrong number of args calling Redis command from script" {run_script "redis.call('incr')" 0} + } + test {Correct handling of reused argv (issue #1939)} { run_script { for i = 0, 10 do