From: Alan T. DeKok Date: Sun, 17 Apr 2022 05:50:50 +0000 (-0400) Subject: remove fr_radius_attr_len() and related checks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94d0d32a10840d878b0742ebfc5b1f2823884caf;p=thirdparty%2Ffreeradius-server.git remove fr_radius_attr_len() and related checks we can just either (a) rely on the input dbuff to see when the data is too long to encode, or (b) just check vp->vp_length --- diff --git a/src/protocols/radius/base.c b/src/protocols/radius/base.c index 561e4923a46..89c7d1080a2 100644 --- a/src/protocols/radius/base.c +++ b/src/protocols/radius/base.c @@ -200,27 +200,6 @@ bool const fr_request_packets[FR_RADIUS_CODE_MAX + 1] = { }; -/** Return the on-the-wire length of an attribute value - * - * @param[in] vp to return the length of. - * @return the length of the attribute. - */ -size_t fr_radius_attr_len(fr_pair_t const *vp) -{ - switch (vp->vp_type) { - case FR_TYPE_VARIABLE_SIZE: - if (vp->da->flags.length) return vp->da->flags.length; /* Variable type with fixed length */ - return vp->vp_length; - - case FR_TYPE_STRUCTURAL: - fr_assert_fail(NULL); - return 0; - - default: - return fr_radius_attr_sizes[vp->vp_type][0]; - } -} - /** Do Ascend-Send / Recv-Secret calculation. * * The secret is hidden by xoring with a MD5 digest created from diff --git a/src/protocols/radius/encode.c b/src/protocols/radius/encode.c index f0b29072f74..0426af1072a 100644 --- a/src/protocols/radius/encode.c +++ b/src/protocols/radius/encode.c @@ -451,20 +451,6 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, fr_dbuff_marker(&src, &value_dbuff); fr_dbuff_marker(&dest, &value_dbuff); - /* - * Set up the default sources for the data. - */ - len = fr_radius_attr_len(vp); - - /* - * Invalid value, don't encode. - */ - if (len > RADIUS_MAX_STRING_LENGTH) { - fr_strerror_printf("%s length of %zu bytes exceeds maximum value length", - vp->da->name, len); - return PAIR_ENCODE_SKIPPED; - } - switch (da->type) { /* * IPv4 addresses are normal, but IPv6 addresses are special to RADIUS. @@ -872,7 +858,7 @@ static ssize_t encode_concat(fr_dbuff_t *dbuff, FR_PROTO_STACK_PRINT(da_stack, depth); p = vp->vp_octets; - data_len = fr_radius_attr_len(vp); + data_len = vp->vp_length; fr_dbuff_marker(&hdr, &work_dbuff); while (data_len > 0) { @@ -1510,17 +1496,15 @@ ssize_t fr_radius_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *enc */ case FR_TYPE_STRING: case FR_TYPE_OCTETS: - if (fr_radius_attr_len(vp) != 0) break; - /* * Zero-length strings are allowed for CUI * (thanks WiMAX!), and for * Message-Authenticator, because we will * automagically generate that one ourselves. */ - if (!fr_dict_attr_is_top_level(vp->da) || - ((vp->da->attr != FR_CHARGEABLE_USER_IDENTITY) && - (vp->da->attr != FR_MESSAGE_AUTHENTICATOR))) { + if ((vp->vp_length == 0) && + (vp->da != attr_chargeable_user_identity) && + (vp->da != attr_message_authenticator)) { fr_dcursor_next(cursor); fr_strerror_const("Zero length string attributes not allowed"); return PAIR_ENCODE_SKIPPED; diff --git a/src/protocols/radius/radius.h b/src/protocols/radius/radius.h index 256e3d44881..6a15ec9c6e1 100644 --- a/src/protocols/radius/radius.h +++ b/src/protocols/radius/radius.h @@ -108,8 +108,6 @@ enum { /* * protocols/radius/base.c */ -size_t fr_radius_attr_len(fr_pair_t const *vp); - int fr_radius_sign(uint8_t *packet, uint8_t const *original, uint8_t const *secret, size_t secret_len) CC_HINT(nonnull (1,3)); int fr_radius_verify(uint8_t *packet, uint8_t const *original,