From: Nick Porter Date: Fri, 12 Apr 2024 10:20:11 +0000 (+0100) Subject: Allow for mulit-pair call env to produce array of pointers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98796a8d3fd0618ffe5f42ee6c04921a80cfcfd6;p=thirdparty%2Ffreeradius-server.git Allow for mulit-pair call env to produce array of pointers where the pointers to the original tmpl or pointer produced by custom parser are required. --- diff --git a/src/lib/unlang/call_env.c b/src/lib/unlang/call_env.c index d1490a44d72..b1db08a13ff 100644 --- a/src/lib/unlang/call_env.c +++ b/src/lib/unlang/call_env.c @@ -153,6 +153,22 @@ static unlang_action_t call_env_expand_start(UNUSED rlm_rcode_t *p_result, UNUSE * If we only need the tmpl or data, just set the pointer and move the next. */ out = (void **)((uint8_t *)*call_env_rctx->data + env->rule->pair.parsed.offset); + + /* + * For multi pair options, the pointers need to go into a new array. + * When processing the first expansion, allocate the array, and for + * all expansions adjust the `out` pointer to write to. + */ + if (call_env_multi(env->rule->flags)) { + void *array; + if (env->multi_index == 0) { + MEM(array = talloc_zero_array((*call_env_rctx->data), void *, env->count)); + *out = array; + } + array = *(void **)out; + out = (void **)((uint8_t *)array + sizeof(void *) * env->multi_index); + } + switch (env->rule->pair.parsed.type) { case CALL_ENV_PARSE_TYPE_TMPL: *out = UNCONST(tmpl_t *, env->data.tmpl);