]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Change length to operate on incoming boxes instead of using an attribute ref
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Feb 2019 10:15:38 +0000 (18:15 +0800)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 28 Feb 2019 10:15:38 +0000 (18:15 +0800)
The general rule is that refs are only used where information from the VALUE_PAIR is required

src/lib/server/xlat_func.c
src/tests/keywords/escape-sequences
src/tests/keywords/length
src/tests/keywords/randstr
src/tests/keywords/truncation
src/tests/modules/cache_rbtree/cache-bin.unlang

index 7f37b434c39506b15e9f322f73230fd1b384a567..c37a59786b332d49cb9bcc4acb9d8feab174e027 100644 (file)
@@ -216,46 +216,26 @@ static xlat_action_t xlat_func_strlen(TALLOC_CTX *ctx, fr_cursor_t *out,
        return XLAT_ACTION_DONE;
 }
 
-/** Return the on-the-wire size of the attribute(s) in bytes
+/** Return the on-the-wire size of the boxes in bytes
  *
  */
 static xlat_action_t xlat_func_length(TALLOC_CTX *ctx, fr_cursor_t *out,
-                                     REQUEST *request, UNUSED void const *xlat_inst,
+                                     UNUSED REQUEST *request, UNUSED void const *xlat_inst,
                                      UNUSED void *xlat_thread_inst, fr_value_box_t **in)
 
 {
-       VALUE_PAIR      *vp;
        fr_value_box_t  *vb;
-       fr_cursor_t     *cursor;
-
-       if (!*in) {
-               REDEBUG("Missing attribute reference");
-               return XLAT_ACTION_FAIL;
-       }
-
-       /*
-        *      Concatenate input boxes to form the reference
-        */
-       if (fr_value_box_list_concat(ctx, *in, in, FR_TYPE_STRING, true) < 0) {
-               RPEDEBUG("Failed concatenating input string for attribute reference");
-               return XLAT_ACTION_FAIL;
-       }
-
-       if (xlat_fmt_to_cursor(NULL, &cursor, NULL, request, (*in)->vb_strvalue) < 0) return XLAT_ACTION_FAIL;
+       fr_cursor_t     cursor;
 
-       MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_SIZE, NULL, false));
-       vb->vb_size = 0;
+       for (vb = fr_cursor_talloc_init(&cursor, in, fr_value_box_t);
+            vb;
+            vb = fr_cursor_next(&cursor)) {
+            fr_value_box_t *new;
 
-       /*
-        *      Get the length of all VPs
-        */
-       for (vp = fr_cursor_head(cursor);
-            vp;
-            vp = fr_cursor_next(cursor)) {
-               vb->vb_size += fr_value_box_network_length(&vp->data);
+               MEM(new = fr_value_box_alloc(ctx, FR_TYPE_SIZE, NULL, false));
+               new->vb_size = fr_value_box_network_length(vb);
+               fr_cursor_append(out, new);
        }
-       talloc_free(cursor);
-       fr_cursor_append(out, vb);
 
        return XLAT_ACTION_DONE;
 }
index 17d708c1d6075315c9e51f478337f1d8e0f5241a..49a936db678b51ce42d92abc82abbe24268b425c 100644 (file)
@@ -18,11 +18,11 @@ update request {
 }
 
 
-if ("%{length:Tmp-String-0}" != 39) {
+if ("%{length:%{Tmp-String-0}}" != 39) {
        test_fail
 }
 
-if ("%{length:Tmp-String-1}" != 42) {
+if ("%{length:%{Tmp-String-1}}" != 42) {
        test_fail
 }
 
index 848d0bca6ef084cc95bc5dd1751c0f8df36e76b9..2679d11f5c80dd5ad8eb076bd22ed53a6b1c56c3 100644 (file)
@@ -23,7 +23,7 @@ abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
 }
 
 update request {
-       &Tmp-Integer-0        := "%{length:Tmp-String-0}"
+       &Tmp-Integer-0        := "%{length:%{Tmp-String-0}}"
 }
 
 if (&Tmp-Integer-0 != 260) {
@@ -31,16 +31,16 @@ if (&Tmp-Integer-0 != 260) {
 }
 
 update request {
-       &Tmp-Integer-0        := "%{length:Tmp-String-2}"
-       &Tmp-Integer-1        := "%{length:Tmp-Octets-0}"
-       &Tmp-Integer-2        := "%{length:Tmp-IP-Address-0}"
-       &Tmp-Integer-3        := "%{length:Tmp-Date-0}"
-       &Tmp-Integer-4        := "%{length:Tmp-Integer-0}"
-       &Tmp-Integer-5        := "%{length:Tmp-Cast-Abinary}"
-       &Tmp-Integer-6        := "%{length:Tmp-Cast-Ifid}"
-       &Tmp-Integer-7        := "%{length:Tmp-Cast-IPv6Addr}"
-       &Tmp-Integer-8        := "%{length:Tmp-Cast-IPv6Prefix}"
-       &Tmp-Integer-9        := "%{length:Tmp-Cast-Byte}"
+       &Tmp-Integer-0        := "%{length:%{Tmp-String-2}}"
+       &Tmp-Integer-1        := "%{length:%{Tmp-Octets-0}}"
+       &Tmp-Integer-2        := "%{length:%{Tmp-IP-Address-0}}"
+       &Tmp-Integer-3        := "%{length:%{Tmp-Date-0}}"
+       &Tmp-Integer-4        := "%{length:%{Tmp-Integer-0}}"
+       &Tmp-Integer-5        := "%{length:%{Tmp-Cast-Abinary}}"
+       &Tmp-Integer-6        := "%{length:%{Tmp-Cast-Ifid}}"
+       &Tmp-Integer-7        := "%{length:%{Tmp-Cast-IPv6Addr}}"
+       &Tmp-Integer-8        := "%{length:%{Tmp-Cast-IPv6Prefix}}"
+       &Tmp-Integer-9        := "%{length:%{Tmp-Cast-Byte}}"
 }
 
 # String - bin 0x39383730
@@ -94,10 +94,10 @@ if (&Tmp-Integer-9 != 1) {
 }
 
 update request {
-       &Tmp-Integer-0        := "%{length:Tmp-Cast-Short}"
-       &Tmp-Integer-1        := "%{length:Tmp-Cast-Ether}"
-       &Tmp-Integer-2        := "%{length:Tmp-Cast-Integer64}"
-       &Tmp-Integer-3        := "%{length:Tmp-Cast-IPv4Prefix}"
+       &Tmp-Integer-0        := "%{length:%{Tmp-Cast-Short}}"
+       &Tmp-Integer-1        := "%{length:%{Tmp-Cast-Ether}}"
+       &Tmp-Integer-2        := "%{length:%{Tmp-Cast-Integer64}}"
+       &Tmp-Integer-3        := "%{length:%{Tmp-Cast-IPv4Prefix}}"
 }
 
 # short - bin 0x373b
index 8e400000cb4ea64793fd14cbed476081e0063629..f33abe345d8c1f9e533c2ef02bb65082ae447fba 100644 (file)
@@ -42,7 +42,7 @@ if (&Tmp-String-4 != "") {
 #
 #  Check repitition of binary output
 #
-if ("%{strlen:%{Tmp-String-5}}" != 10) {
+if ("%{length:%{Tmp-String-5}}" != 10) {
        test_fail
 }
 
index f3217ad99aa40acd434f0b62bac4103f34bff818..bdcff618b08804a05a13a0f93cb4c64501238311 100644 (file)
@@ -76,7 +76,7 @@ a02f4a3ab98d75992d68a15d393387fe9ef01041569570ad6fe884764e55567311bcacfcffae7655
 
 # Actual length of octet string is 4083 bytes
 update request {
-       &Tmp-Integer-0 := "%{length:Tmp-Octets-0}"
+       &Tmp-Integer-0 := "%{length:%{Tmp-Octets-0}}"
 }
 
 if (&Tmp-Integer-0 != 4083) {
@@ -92,7 +92,7 @@ update request {
        &Tmp-String-0 := "%{1}"
 }
 
-if ("%{length:Tmp-String-0}" != 8166) {
+if ("%{length:%{Tmp-String-0}}" != 8166) {
        test_fail
 }
 
index 0fdc47b57cb45c731927f4d8f12bf93881c36746..abe5d3eb00722defea10756b2984ee1d90fb6428 100644 (file)
@@ -60,7 +60,7 @@ else {
        test_fail
 }
 
-if ("%{length:Tmp-String-1}" == 11) {
+if ("%{length:%{Tmp-String-1}}" == 11) {
        test_pass
 }
 else {
@@ -91,7 +91,7 @@ else {
        test_fail
 }
 
-if ("%{length:Tmp-String-1}" == 7) {
+if ("%{length:%{Tmp-String-1}}" == 7) {
        test_pass
 }
 else {
@@ -159,7 +159,7 @@ else {
        test_fail
 }
 
-if ("%{length:Tmp-String-1}" == 11) {
+if ("%{length:%{Tmp-String-1}}" == 11) {
        test_pass
 }
 else {
@@ -190,7 +190,7 @@ else {
        test_fail
 }
 
-if ("%{length:Tmp-String-1}" == 7) {
+if ("%{length:%{Tmp-String-1}}" == 7) {
        test_pass
 }
 else {