]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Revert "fix decode_args() function"
authorAlan T. DeKok <aland@freeradius.org>
Fri, 13 Jan 2023 17:20:11 +0000 (12:20 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 13 Jan 2023 17:20:11 +0000 (12:20 -0500)
This reverts commit 0aa0f42d90b15366ab79ac364d55b45cffae7a60.

src/protocols/tacacs/decode.c

index 341efdd5ca6e9c03cf45cf4f3bdf5305b9d933ab..75d263f94bdddb1f4b37355b3d9f00d134bc2834 100644 (file)
 /**
  *     Decode a TACACS+ 'arg_N' fields.
  */
-static int tacacs_decode_args(TALLOC_CTX *ctx, fr_pair_list_t *out,
-                             uint8_t arg_cnt, uint8_t const *arg_list, uint8_t const *end)
+static int tacacs_decode_args(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
+                             uint8_t arg_cnt, uint8_t const *arg_list, uint8_t const *data, uint8_t const *end)
 {
        uint8_t i;
-       uint8_t const *p;
+       uint8_t const *p = data;
        fr_pair_t *vp;
 
        /*
@@ -82,26 +82,24 @@ static int tacacs_decode_args(TALLOC_CTX *ctx, fr_pair_list_t *out,
         */
        if (!arg_cnt) return 0;
 
-       if ((arg_list + arg_cnt) > end) {
+       if ((p + arg_cnt) > end) {
                fr_strerror_printf("Argument count %u overflows the remaining data in the packet", arg_cnt);
                return -1;
        }
 
-       p = arg_list + arg_cnt;
-
        /*
         *      Check for malformed packets before anything else.
         */
        for (i = 0; i < arg_cnt; i++) {
                if ((p + arg_list[i]) > end) {
-                       fr_strerror_printf("TACACS+ argument %u length %u overflows the remaining data (%zu) in the packet",
-                                          i, arg_list[i], end - p);
+                       fr_strerror_printf("'%s' argument %u length %u overflows the remaining data (%zu) in the packet",
+                                          parent->name, i, arg_list[i], end - p);
                        return -1;
                }
 
                p += arg_list[i];
        }
-       p = arg_list + arg_cnt;
+       p = data;
 
        /*
         *      Then, do the dirty job of creating attributes.
@@ -146,7 +144,7 @@ static int tacacs_decode_args(TALLOC_CTX *ctx, fr_pair_list_t *out,
                         *
                         *      Argument-List += "name=value"
                         */
-                       da = attr_tacacs_argument_list;
+                       da = parent;
                        value = p;
                        arg_end = p + arg_list[i];
                }
@@ -192,7 +190,7 @@ static int tacacs_decode_args(TALLOC_CTX *ctx, fr_pair_list_t *out,
                        if (fr_pair_value_from_str(vp, (char const *) value, arg_end - value, NULL, true) < 0) {
                        fail:
                                talloc_free(vp);
-                               if (da != attr_tacacs_argument_list) goto raw;
+                               if (da != parent) goto raw;
 
                                goto next;
                        }
@@ -598,7 +596,8 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *bu
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, out, pkt->author_req.arg_cnt, p, end) < 0) goto fail;
+                       if (tacacs_decode_args(ctx, out, attr_tacacs_argument_list,
+                                              pkt->author_req.arg_cnt, BODY(author_req), p, end) < 0) goto fail;
 
                } else if (packet_is_author_response(pkt)) {
                        /*
@@ -648,7 +647,8 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *bu
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, out, pkt->author_res.arg_cnt, p, end) < 0) goto fail;
+                       if (tacacs_decode_args(ctx, out, attr_tacacs_argument_list,
+                                       pkt->author_res.arg_cnt, BODY(author_res), p, end) < 0) goto fail;
 
                } else {
                        goto unknown_packet;
@@ -710,7 +710,8 @@ ssize_t fr_tacacs_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *bu
                        /*
                         *      Decode 'arg_N' arguments (horrible format)
                         */
-                       if (tacacs_decode_args(ctx, out, pkt->acct_req.arg_cnt, p, end) < 0) goto fail;
+                       if (tacacs_decode_args(ctx, out, attr_tacacs_argument_list,
+                                       pkt->acct_req.arg_cnt, BODY(acct_req), p, end) < 0) goto fail;
 
                } else if (packet_is_acct_reply(pkt)) {
                        /**