From: Arran Cudbard-Bell Date: Sun, 16 Apr 2023 22:28:17 +0000 (+1000) Subject: redis: Deal with first func argument specially X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f6d5c4b1a897d118a4c8068898360ca11be4665;p=thirdparty%2Ffreeradius-server.git redis: Deal with first func argument specially Make sure it's an integer, and don't require future varidic arguments to be non-null --- diff --git a/src/modules/rlm_redis/rlm_redis.c b/src/modules/rlm_redis/rlm_redis.c index afe3b8dce7d..222e7d5be95 100644 --- a/src/modules/rlm_redis/rlm_redis.c +++ b/src/modules/rlm_redis/rlm_redis.c @@ -350,7 +350,8 @@ static xlat_action_t redis_node_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, } static xlat_arg_parser_t const redis_lua_func_args[] = { - { .required = true, .variadic = true, .concat = true, .type = FR_TYPE_STRING }, + { .required = true, .single = true, .type = FR_TYPE_UINT64 }, /* key count */ + { .variadic = true, .concat = true, .type = FR_TYPE_STRING }, /* keys and args */ XLAT_ARG_PARSER_TERMINATOR }; @@ -377,12 +378,22 @@ static xlat_action_t redis_lua_func_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, char const *argv[MAX_REDIS_ARGS]; size_t arg_len[MAX_REDIS_ARGS]; int argc; + char key_count[sizeof("184467440737095551615")]; uint8_t const *key = NULL; size_t key_len = 0; xlat_action_t action = XLAT_ACTION_DONE; fr_value_box_t *vb_out; + /* + * First argument is always the key count + */ + if (unlikely(fr_value_box_print(&FR_SBUFF_OUT(key_count, sizeof(key_count)), fr_value_box_list_head(in), NULL) < 0)) { + RPERROR("Failed converting key count to string"); + return XLAT_ACTION_FAIL; + } + fr_value_box_list_talloc_free_head(in); + /* * Try EVALSHA first, and if that fails fall back to SCRIPT LOAD */ @@ -390,7 +401,9 @@ static xlat_action_t redis_lua_func_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, arg_len[0] = sizeof("EVALSHA") - 1; argv[1] = func->digest; arg_len[1] = sizeof(func->digest) - 1; - argc = 2; + argv[2] = key_count; + arg_len[2] = strlen(key_count); + argc = 3; fr_value_box_list_foreach(in, vb) { if (argc == NUM_ELEMENTS(argv)) { diff --git a/src/tests/modules/redis/functions.unlang b/src/tests/modules/redis/functions.unlang index 7190dd57529..a21f37ee347 100644 --- a/src/tests/modules/redis/functions.unlang +++ b/src/tests/modules/redis/functions.unlang @@ -12,6 +12,13 @@ if (!(%(redis.hello_world:0) == 'hello world')) { test_fail } +# ...and again using an argument that would produce a null result +# this is a regression test where the arg parser would require all +# arguments to be non-null if the first argument was +if (!(%(redis.hello_world:0 %{Framed-IP-Address}) == 'hello world')) { + test_fail +} + if (!(%(redis.concat_args_keys:1 foo bar baz) == 'foo,bar,baz')) { test_fail }