]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix tests for unknown attrs in struct
authorAlan T. DeKok <aland@freeradius.org>
Sun, 27 Oct 2019 13:13:53 +0000 (09:13 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 27 Oct 2019 13:13:53 +0000 (09:13 -0400)
and fix code :(

src/lib/util/struct.c
src/tests/unit/radius_struct.txt

index 8364b9cebe6a0086dcf93916259d4ebce8b06b8d..48f7fca996bbf8a501553866a0d6286628d3e1e7 100644 (file)
@@ -334,29 +334,45 @@ ssize_t fr_struct_to_network(uint8_t *out, size_t outlen,
                 *      Nothing more to do, or we've done all of the
                 *      entries in this structure, stop.
                 */
-               if (!vp || (vp->da->parent != parent)) break;
+               if (!vp || (vp->da->parent != parent)) {
+                       break;
+               }
        }
 
        if (!vp || !outlen) return p - out;
 
        /*
-        *      If our parent is a struct, AND it's parent is
-        *      the key_da, then we have a keyed struct for
-        *      the child.  Go encode it.
+        *      Check for keyed data to encode.
         */
-       if (key_da &&
-           (vp->da->parent->type == FR_TYPE_STRUCT) &&
-           (vp->da->parent->parent == key_da)) {
-               len = fr_struct_to_network(p, outlen,
-                                          vp->da->parent, cursor);
-               if (len < 0) return len;
-               return (p - out) + len;
+       if (key_da) {
+               /*
+                *      If our parent is a struct, AND it's parent is
+                *      the key_da, then we have a keyed struct for
+                *      the child.  Go encode it.
+                */
+               if ((vp->da->parent->parent == key_da) &&
+                   (vp->da->parent->type == FR_TYPE_STRUCT)) {
+                       len = fr_struct_to_network(p, outlen,
+                                                  vp->da->parent, cursor);
+                       if (len < 0) return len;
+                       return (p - out) + len;
+               }
+
+               /*
+                *      The next VP is likely octets and unknown.
+                */
+               if ((vp->da->parent == key_da) &&
+                   (vp->da->type != FR_TYPE_TLV)) {
+                       len = fr_value_box_to_network(NULL, p, outlen, &vp->data);
+                       if (len <= 0) return -1;
+                       (void) fr_cursor_next(cursor);
+                       return (p - out) + len;
+               }
+
+               /*
+                *      We have no idea what to do.  Ignore it.
+                */
        }
-       /*
-        *      Else we have a key_da with no child struct.
-        *      Oh well.  Assume that the caller knows WTF
-        *      he's doing, and encode things as best we can.
-        */
 
        return p - out;
 }
index 218250f3206b0917edb124f5490c1617c06b7061..4c05863b5b5dff4393d741ae8be28003b1f4debf 100644 (file)
@@ -68,7 +68,7 @@ decode-pair ff 0d 02 00 00 1a 99 ff fe fd fc fb fa
 match Key-Field = 2, Filler = 6809, Attr-255.1.2 = 0xfffefdfcfbfa
 
 encode-pair -
-match ff 0f 02 00 00 1a 99 02 08 ff fe fd fc fb fa
+match ff 0d 02 00 00 1a 99 ff fe fd fc fb fa
 
 
 count