]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
check if key exists before updating it
authorAlan T. DeKok <aland@freeradius.org>
Sat, 14 Sep 2024 21:00:34 +0000 (17:00 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 14 Sep 2024 21:00:34 +0000 (17:00 -0400)
src/lib/unlang/foreach.c

index 85b7bb1a65e7a218bfcc9eb02c5319635e18f6d1..4ae6621d1324fed5e25942036a5512c1ec0f0573 100644 (file)
@@ -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);