From 51f9bed3dd8d35a59e9124e49450c9795822dbf5 Mon Sep 17 00:00:00 2001 From: "Meir Shpilraien (Spielrein)" Date: Tue, 18 Jan 2022 10:29:52 +0200 Subject: [PATCH] Fix `FUNCTION LOAD` ignores unknown parameter. (#10131) Following discussion on: https://github.com/redis/redis/issues/9899#issuecomment-1014689385 Raise error if unknows parameter is given to `FUNCTION LOAD`. Before the fix: ``` 127.0.0.1:6379> function load LUA lib2 foo bar "local function test1() return 5 end redis.register_function('test1', test1)" OK ``` After the fix: ``` 127.0.0.1:6379> function load LUA lib2 foo bar "local function test1() return 5 end redis.register_function('test1', test1)" (error) ERR Unkowns option given: foo ``` --- src/functions.c | 2 ++ tests/unit/functions.tcl | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/functions.c b/src/functions.c index 76e8c21d7..90e36231e 100644 --- a/src/functions.c +++ b/src/functions.c @@ -966,6 +966,8 @@ void functionLoadCommand(client *c) { desc = c->argv[argc_pos++]->ptr; continue; } + addReplyErrorFormat(c, "Unknown option given: %s", (char*)next_arg->ptr); + return; } if (argc_pos >= c->argc) { diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl index 48f846e20..6ad61fb5f 100644 --- a/tests/unit/functions.tcl +++ b/tests/unit/functions.tcl @@ -12,6 +12,13 @@ start_server {tags {"scripting"}} { r fcall test 0 } {hello} + test {FUNCTION - Load with unknown argument} { + catch { + r function load LUA test foo bar [get_function_code test {return 'hello'}] + } e + set _ $e + } {*Unknown option given*} + test {FUNCTION - Create an already exiting library raise error} { catch { r function load LUA test [get_function_code test {return 'hello1'}]