]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix overwriting values at specific indexes e.g. reply:Reply-Message[1] = 'foo'
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 16 May 2015 19:50:07 +0000 (15:50 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 16 May 2015 20:08:51 +0000 (16:08 -0400)
src/main/map.c
src/tests/keywords/update-index [new file with mode: 0644]

index c86a985368640c65990765e36a14e263c1675847..b7d8c24bbe82097807b657cfe7a90cbb41055375 100644 (file)
@@ -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 (file)
index 0000000..390aca7
--- /dev/null
@@ -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'
+       }
+}
+