From: Arran Cudbard-Bell Date: Sun, 4 Sep 2022 04:19:43 +0000 (-0400) Subject: Use fr_sbuff_error in more places X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1664880e98dc4e47db7a21a044ca7c227ba0d1c;p=thirdparty%2Ffreeradius-server.git Use fr_sbuff_error in more places --- diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index b2bfaef18dc..b81ec321f0c 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -1326,7 +1326,8 @@ static fr_slen_t tmpl_attr_parse_filter(tmpl_attr_error_t *err, tmpl_attr_t *ar, if (t_rules->disallow_filters) { fr_strerror_const("Filters not allowed here"); if (err) *err = TMPL_ATTR_ERROR_FILTER_NOT_ALLOWED; - return -1; /* Error at index 0 */ + fr_sbuff_set_to_start(&our_name); + return fr_sbuff_error(&our_name); } ar->ar_filter_type = TMPL_ATTR_FILTER_TYPE_INDEX; @@ -1420,7 +1421,6 @@ int tmpl_attr_afrom_attr_unresolved_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *e int ret; char *unresolved; size_t len; - fr_slen_t slen; if (depth > FR_DICT_MAX_TLV_STACK) { fr_strerror_const("Attribute nesting too deep"); @@ -1474,11 +1474,8 @@ int tmpl_attr_afrom_attr_unresolved_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *e .ar_parent = parent, }; - slen = tmpl_attr_parse_filter(err, ar, name, t_rules); - if (slen < 0) { - fr_sbuff_advance(name, -slen); - goto error; - } + if (tmpl_attr_parse_filter(err, ar, name, t_rules) < 0) goto error; + /* * Insert the ar into the list of attribute references */ @@ -1550,7 +1547,7 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t if (err) *err = TMPL_ATTR_ERROR_NESTING_TOO_DEEP; error: fr_sbuff_marker_release(&m_s); - return -1; + return fr_sbuff_error(name); } /* @@ -1825,11 +1822,7 @@ do_suffix: * - The type of attribute. * - If this is the leaf attribute reference. */ - slen = tmpl_attr_parse_filter(err, ar, name, t_rules); - if (slen < 0) { - fr_sbuff_advance(name, -slen); - goto error; - } + if (tmpl_attr_parse_filter(err, ar, name, t_rules) < 0) goto error; /* * At the end of the attribute reference. If there's a @@ -2184,7 +2177,6 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, } else if (slen > 0) { /* Found a filter */ tmpl_attr_list_insert_tail(&vpt->data.attribute.ar, ar); } else if (slen < 0) { /* Filter error */ - fr_sbuff_advance(&our_name, -slen); goto error; } vpt->type = TMPL_TYPE_LIST; @@ -3350,7 +3342,7 @@ ssize_t tmpl_cast_from_substr(tmpl_rules_t *rules, fr_sbuff_t *in) } if (fr_type_is_non_leaf(cast)) { fr_strerror_printf("Forbidden data type '%s' in cast", fr_type_to_str(cast)); - FR_SBUFF_MARKER_ERROR_RETURN(&m); + FR_SBUFF_ERROR_RETURN(&m); } if (!fr_sbuff_next_if_char(&our_in, close)) { diff --git a/src/lib/util/sbuff.h b/src/lib/util/sbuff.h index fc2db1a06d7..95136eb15b9 100644 --- a/src/lib/util/sbuff.h +++ b/src/lib/util/sbuff.h @@ -970,12 +970,7 @@ static inline fr_slen_t _fr_sbuff_error(fr_sbuff_t *sbuff, char const *err) /** Return the current position in the sbuff as a negative offset * */ -#define FR_SBUFF_ERROR_RETURN(_sbuff) return -(fr_sbuff_used(_sbuff)) - -/** Return the current position in the sbuff as a negative offset - * - */ -#define FR_SBUFF_MARKER_ERROR_RETURN(_marker) return -(fr_sbuff_used(_marker)) +#define FR_SBUFF_ERROR_RETURN(_sbuff_or_marker) return fr_sbuff_error(_sbuff_or_marker) /** Return the current adjusted position in the sbuff as a negative offset * diff --git a/src/tests/unit/condition/base.txt b/src/tests/unit/condition/base.txt index b10b9a06261..354bee61aad 100644 --- a/src/tests/unit/condition/base.txt +++ b/src/tests/unit/condition/base.txt @@ -145,10 +145,10 @@ match &Filter-Id == &Framed-IP-Address # user forces incompatible types, then that's an error. # condition &Filter-Id == &Framed-IP-Address -match ERROR offset 23: Unknown data type +match ERROR offset 24: Unknown data type condition &Filter-Id == "foo" -match ERROR offset 1: Unknown data type +match ERROR offset 2: Unknown data type # # Normalize things @@ -397,7 +397,7 @@ match &User-Name # Forbidden data types in cast # condition ("foo" == &User-Name) -match ERROR offset 2: Forbidden data type 'vsa' in cast +match ERROR offset 3: Forbidden data type 'vsa' in cast # # If the LHS is a cast to a type, and the RHS is an attribute @@ -430,7 +430,7 @@ match &Tmp-uint64-0 == &reply.Foo-Stuff-Bar # Casting attributes of different size # condition &Tmp-uint64-0 == &Framed-IP-Address -match ERROR offset 8: Cannot cast type 'uint64' to 'ipaddr' +match ERROR offset 9: Cannot cast type 'uint64' to 'ipaddr' # # LHS is a prefix, which _might_ be castable to an address @@ -531,17 +531,17 @@ condition request.Foo+Bar == request.Foo+Bar match true condition &request.Foo+Bar == 'request.Foo+Bar' -match ERROR offset 12: Unexpected text after attribute reference +match ERROR offset 13: Unexpected text after attribute reference condition 'request.Foo+d' == &request.Foo+Bar -match ERROR offset 31: Unexpected text after attribute reference +match ERROR offset 32: Unexpected text after attribute reference # Attribute tags are not allowed for unknown attributes condition &request.FooBar:0 == &request.FooBar -match ERROR offset 15: Unexpected text after attribute reference +match ERROR offset 16: Unexpected text after attribute reference condition ¬-a-list:User-Name == ¬-a-list:User-Name -match ERROR offset 11: Unexpected text after attribute reference +match ERROR offset 12: Unexpected text after attribute reference # . is a valid dictionary name attribute, so we can't error out in pass1 condition ¬-a-packet.User-Name == ¬-a-packet.User-Name diff --git a/src/tests/unit/condition/nested.txt b/src/tests/unit/condition/nested.txt index af5e745fe8b..d10f723b58d 100644 --- a/src/tests/unit/condition/nested.txt +++ b/src/tests/unit/condition/nested.txt @@ -40,11 +40,11 @@ match ERROR offset 48: No closing ']' for array index # Too many dots, point to the thing that's wrong condition &Vendor-Specific.WiMAX.Packet-Flow-Descriptor..Uplink-QOS-Id[0] -match ERROR offset 46: Zero length attribute name: Unresolved attributes are not allowed here +match ERROR offset 47: Zero length attribute name: Unresolved attributes are not allowed here # Trailing dots, point to the dot that's an error condition &Vendor-Specific.WiMAX.Packet-Flow-Descriptor.Uplink-QOS-Id[0]. -match ERROR offset 62: Parent type of nested attribute Uplink-QOS-Id must be of type "struct", "tlv", "vendor", "vsa" or "group", got "uint8" +match ERROR offset 63: Parent type of nested attribute Uplink-QOS-Id must be of type "struct", "tlv", "vendor", "vsa" or "group", got "uint8" count match 19 diff --git a/src/tests/unit/xlat/base.txt b/src/tests/unit/xlat/base.txt index a8ae03326d2..d968aac0ded 100644 --- a/src/tests/unit/xlat/base.txt +++ b/src/tests/unit/xlat/base.txt @@ -239,10 +239,10 @@ xlat %{ } match ERROR offset 2: Invalid char ' ' in expression xlat %{\t} -match ERROR offset 2: Invalid attribute name +match ERROR offset 3: Invalid attribute name xlat %{\n} -match ERROR offset 2: Invalid attribute name +match ERROR offset 3: Invalid attribute name xlat %{foo } match ERROR offset 5: Invalid char ' ' in expression diff --git a/src/tests/unit/xlat/cond_base.txt b/src/tests/unit/xlat/cond_base.txt index 92c0ad16ddb..87ff2021817 100644 --- a/src/tests/unit/xlat/cond_base.txt +++ b/src/tests/unit/xlat/cond_base.txt @@ -24,7 +24,7 @@ xlat_purify (|| b) match ERROR offset 2: No operand found. Expected &ref, literal, 'quoted literal', "%{expansion}", or enum value xlat_purify ((ok || handled) foo) -match ERROR offset 17: Invalid operator +match ERROR offset 18: Invalid operator # escapes in names are illegal xlat_purify (ok\ foo || handled) @@ -37,10 +37,10 @@ xlat_purify (&Service-Type == 000-111) match (&Service-Type == NULL) xlat_purify (ok FOO handled) -match ERROR offset 4: Invalid operator +match ERROR offset 5: Invalid operator xlat_purify (ok !x handled) -match ERROR offset 4: Invalid operator +match ERROR offset 5: Invalid operator xlat_purify (ok =x handled) match ERROR offset 4: Invalid operator @@ -481,7 +481,7 @@ match (&Tmp-uint64-0 == &reply.Tmp-String-0) # Casting attributes of different size # xlat_purify &Tmp-uint64-0 == &Framed-IP-Address -match ERROR offset 8: Cannot cast type 'uint64' to 'ipaddr' +match ERROR offset 9: Cannot cast type 'uint64' to 'ipaddr' # # LHS is a prefix, which _might_ be castable to an address @@ -550,7 +550,7 @@ match (&raw.26.24757.84.9.5.7 == 0x1a99) # This one is really unknown xlat_purify &26.24757.84.9.5.15 == 0x1a99 -match ERROR offset 17: Unknown attributes not allowed here +match ERROR offset 18: Unknown attributes not allowed here #match &Vendor-Specific.WiMAX.Packet-Flow-Descriptor-v2.Classifier.Src-Spec.15 == 0x1a99 # @@ -578,14 +578,14 @@ xlat_purify request.Foo == 'request.Foo' match true xlat_purify &request.Foo == 'request.Foo' -match ERROR offset 9: Attribute 'Foo' not found in namespace 'internal': Unresolved attributes are not allowed here +match ERROR offset 10: Attribute 'Foo' not found in namespace 'internal': Unresolved attributes are not allowed here xlat_purify ¬-a-list.User-Name == ¬-a-list.User-Name -match ERROR offset 1: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here +match ERROR offset 2: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here # . is a valid dictionary name attribute, so we can't error out in pass1 xlat_purify ¬-a-packet.User-Name == ¬-a-packet.User-Name -match ERROR offset 1: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here +match ERROR offset 2: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here # # The LHS is a string with ASCII 5C 30 30 30 inside of it vs the RHS which should contain ASCII 0.