From: Alan T. DeKok Date: Sun, 27 Oct 2019 13:13:53 +0000 (-0400) Subject: fix tests for unknown attrs in struct X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ea66a56ef73e25e800316b188ce2188ab398f29;p=thirdparty%2Ffreeradius-server.git fix tests for unknown attrs in struct and fix code :( --- diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index 8364b9cebe6..48f7fca996b 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -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; } diff --git a/src/tests/unit/radius_struct.txt b/src/tests/unit/radius_struct.txt index 218250f3206..4c05863b5b5 100644 --- a/src/tests/unit/radius_struct.txt +++ b/src/tests/unit/radius_struct.txt @@ -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