Fix for calling foreach sections at varying depths
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 12 Aug 2014 15:46:41 +0000 (11:46 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 12 Aug 2014 15:47:34 +0000 (11:47 -0400)
src/main/modcall.c
src/tests/keywords/foreach-varied-depth [new file with mode: 0644]

index 6554670..ba166a7 100644 (file)
@@ -724,7 +724,13 @@ redo:
                        }
                } /* loop over VPs */
 
+               /*
+                *      Free the copied vps and the request data
+                *      If we don't remove the request data, something could call
+                *      the xlat outside of a foreach loop and trigger a segv.
+                */
                pairfree(&vps);
+               request_data_get(request, radius_get_vp, foreach_depth);
 
                rad_assert(next != NULL);
                result = next->result;
diff --git a/src/tests/keywords/foreach-varied-depth b/src/tests/keywords/foreach-varied-depth
new file mode 100644 (file)
index 0000000..3c3918d
--- /dev/null
@@ -0,0 +1,43 @@
+update {
+       control:Tmp-String-0 := "ssid=ABCDEF"
+       control:Tmp-String-0 += "ssid=GHIJKL"
+       reply:Filter-Id := "filter"
+}
+
+if (User-Name) {
+       foreach &control:Tmp-String-0 {
+               if ("%{Foreach-Variable-0}" =~ /(.*)/) {
+                       update control {
+                               Tmp-String-1 := "%{1}"
+                       }
+               }
+       }
+}
+
+if (&control:Tmp-String-1 != 'ssid=GHIJKL') {
+       update reply {
+               Filter-Id += 'fail 0'
+       }
+}
+
+update control {
+       Tmp-String-1 !* ANY
+}
+
+foreach &control:Tmp-String-0 {
+       if ("%{Foreach-Variable-0}" =~ /(.*)/) {
+               update control {
+                       Tmp-String-1 := "%{1}"
+               }
+       }
+}
+
+if (&control:Tmp-String-1 != 'ssid=GHIJKL') {
+       update reply {
+               Filter-Id += 'fail 1'
+       }
+}
+
+update control {
+       Tmp-String-1 !* ANY
+}