]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Use fr_sbuff_error in more places
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 04:19:43 +0000 (00:19 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 04:19:43 +0000 (00:19 -0400)
src/lib/server/tmpl_tokenize.c
src/lib/util/sbuff.h
src/tests/unit/condition/base.txt
src/tests/unit/condition/nested.txt
src/tests/unit/xlat/base.txt
src/tests/unit/xlat/cond_base.txt

index b2bfaef18dcf33921874b0554446ee606989d5a1..b81ec321f0c4e8b6d6b6c6fd4a67f8269ee94686 100644 (file)
@@ -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)) {
index fc2db1a06d7365b84138e74325ca7790d797fc35..95136eb15b983de2eab980dc1bd8050fefd11e77 100644 (file)
@@ -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
  *
index b10b9a06261295aa0dc7061fb7b66d84dd1ebb5a..354bee61aadf47684e70f98fee8cdb3648d29828 100644 (file)
@@ -145,10 +145,10 @@ match <ipaddr>&Filter-Id == &Framed-IP-Address
 #  user forces incompatible types, then that's an error.
 #
 condition <ipaddr>&Filter-Id == <blerg>&Framed-IP-Address
-match ERROR offset 23: Unknown data type
+match ERROR offset 24: Unknown data type
 
 condition <blerg>&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 (<vsa>"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 <ipaddr>&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 &not-a-list:User-Name == &not-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 &not-a-packet.User-Name == &not-a-packet.User-Name
index af5e745fe8b22551cebade70cff9bb7594200e91..d10f723b58d21dbe3ac545a9acbda97e7b09deef 100644 (file)
@@ -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
index a8ae03326d21c233fdb6ae57f0d2e5e9bf2432fc..d968aac0dedb1c9607ecebd95bd8f820f82ea5fc 100644 (file)
@@ -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
index 92c0ad16ddbc27ebcd51adea62de981f38912416..87ff20218177242ced00e6219212d8ae795dbe9e 100644 (file)
@@ -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 <ipaddr>&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 &not-a-list.User-Name == &not-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 &not-a-packet.User-Name == &not-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.