From: Arran Cudbard-Bell Date: Sat, 16 May 2015 19:50:07 +0000 (-0400) Subject: Fix overwriting values at specific indexes e.g. reply:Reply-Message[1] = 'foo' X-Git-Tag: release_3_0_9~350 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=143eb49c84a2985af336b5da44a666ae7870c395;p=thirdparty%2Ffreeradius-server.git Fix overwriting values at specific indexes e.g. reply:Reply-Message[1] = 'foo' --- diff --git a/src/main/map.c b/src/main/map.c index c86a9853686..b7d8c24bbe8 100644 --- a/src/main/map.c +++ b/src/main/map.c @@ -1313,11 +1313,12 @@ int map_to_request(REQUEST *request, vp_map_t const *map, radius_map_getvalue_t /* Wind to last instance */ fr_cursor_last(&src_list); if (dst) { - dst = fr_cursor_remove(&dst_list); + dst = fr_cursor_replace(&dst_list, fr_cursor_remove(&src_list)); DEBUG_OVERWRITE(dst, fr_cursor_current(&src_list)); pairfree(&dst); + } else { + fr_cursor_insert(&dst_list, fr_cursor_remove(&src_list)); } - fr_cursor_insert(&dst_list, fr_cursor_remove(&src_list)); /* Free any we didn't insert */ pairfree(&head); break; diff --git a/src/tests/keywords/update-index b/src/tests/keywords/update-index new file mode 100644 index 00000000000..390aca76798 --- /dev/null +++ b/src/tests/keywords/update-index @@ -0,0 +1,52 @@ +# +# PRE: update update-remove-index +# +# A more generic "update" mechanism +# +update { + control:Cleartext-Password := 'hello' + reply:Filter-Id := "filter" +} + +update { + control:Reply-Message += 'a' + control:Reply-Message += 'b' + control:Reply-Message += 'c' +} + +if ((&control:Reply-Message[0] != 'a') || (&control:Reply-Message[1] != 'b') || (&control:Reply-Message[2] != 'c')) { + update { + reply:Filter-Id := 'Fail 0' + } +} + +# Overwrite a specific index, and check the value here is replaced +update { + &control:Reply-Message[1] := 'd' +} + +if ((&control:Reply-Message[0] != 'a') || (&control:Reply-Message[1] != 'd') || (&control:Reply-Message[2] != 'c')) { + update { + reply:Filter-Id := 'Fail 1' + } +} + +# Check isolation... +update { + &control:Reply-Message[0] := &control:Reply-Message[0] +} + +if ((&control:Reply-Message[0] != 'a') || (&control:Reply-Message[1] != 'd') || (&control:Reply-Message[2] != 'c')) { + update { + reply:Filter-Id := 'Fail 2' + } +} + +# Verify we haven't acquired any extra.. + +if ("%{control:Reply-Message[#]}" != 3) { + update { + reply:Filter-Id := 'Fail 3' + } +} +