From: Alan T. DeKok Date: Sat, 14 Sep 2024 21:00:34 +0000 (-0400) Subject: check if key exists before updating it X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4692c07f2ca0e490c5045e2b7e2553f33599f143;p=thirdparty%2Ffreeradius-server.git check if key exists before updating it --- diff --git a/src/lib/unlang/foreach.c b/src/lib/unlang/foreach.c index 85b7bb1a65e..4ae6621d132 100644 --- a/src/lib/unlang/foreach.c +++ b/src/lib/unlang/foreach.c @@ -225,7 +225,7 @@ static int unlang_foreach_xlat_key_update(request_t *request, unlang_frame_state { fr_value_box_t box; - RDEBUG("UPDATE"); + if (!state->key) return 0; fr_value_box_clear_value(&state->key->data); @@ -236,8 +236,6 @@ static int unlang_foreach_xlat_key_update(request_t *request, unlang_frame_state return -1; } - RDEBUG("KEY %pP", state->key); - return 0; } @@ -339,6 +337,8 @@ static unlang_action_t unlang_foreach_xlat_init(rlm_rcode_t *p_result, request_t static void unlang_foreach_attr_key_update(UNUSED request_t *request, unlang_frame_state_foreach_t *state) { + if (state->key) return; + fr_value_box_clear_value(&state->key->data); if (tmpl_dcursor_print(&FR_SBUFF_IN(state->buffer, BUFFER_SIZE), &state->cc) > 0) { fr_value_box_strdup(state->key, &state->key->data, NULL, state->buffer, false); @@ -381,9 +381,7 @@ next: return UNLANG_ACTION_CALCULATE_RESULT; } - if (state->key) { - unlang_foreach_attr_key_update(request, state); - } + unlang_foreach_attr_key_update(request, state); /* * Copy the data. @@ -463,9 +461,7 @@ static unlang_action_t unlang_foreach_attr_init(rlm_rcode_t *p_result, request_t /* * Update the key with the current path or index. */ - if (state->key) { - unlang_foreach_attr_key_update(request, state); - } + unlang_foreach_attr_key_update(request, state); if (vp->vp_type == FR_TYPE_GROUP) { fr_assert(state->value->vp_type == FR_TYPE_GROUP);