]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
redis: Deal with first func argument specially
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 16 Apr 2023 22:28:17 +0000 (08:28 +1000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 16 Apr 2023 22:28:17 +0000 (08:28 +1000)
Make sure it's an integer, and don't require future varidic arguments to be non-null

src/modules/rlm_redis/rlm_redis.c
src/tests/modules/redis/functions.unlang

index afe3b8dce7dc0214a9d3c646bf3e35460140d959..222e7d5be9592e26ae6cf3fb6afe3f07ebfbef6a 100644 (file)
@@ -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)) {
index 7190dd575291ad4a6d8a897f4d14e59e15c7b2a4..a21f37ee347e47ce71921ed9b2b5a499a2cedf71 100644 (file)
@@ -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
 }