From: Nick Porter Date: Thu, 15 Oct 2020 07:27:19 +0000 (+0100) Subject: Remove vp->next from decode.c X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4ac5739a7fd3afbf0b312a23b5ea2f79f409dc8;p=thirdparty%2Ffreeradius-server.git Remove vp->next from decode.c . --- diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index 0fc82dbcbaa..31e46e071ab 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -279,6 +279,7 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat fr_io_track_t const *track = talloc_get_type_abort_const(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; RADCLIENT const *client; + fr_cursor_t cursor; fr_assert(data[0] < FR_RADIUS_MAX_PACKET_CODE); @@ -307,9 +308,10 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat * That MUST be set and checked in the underlying * transport, via a call to fr_radius_ok(). */ + fr_cursor_init(&cursor, &request->request_pairs); if (fr_radius_decode(request->packet, request->packet->data, request->packet->data_len, NULL, client->secret, talloc_array_length(client->secret) - 1, - &request->request_pairs) < 0) { + &cursor) < 0) { RPEDEBUG("Failed decoding packet"); return -1; } @@ -332,7 +334,6 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat * values. */ if (!client->active) { - fr_cursor_t cursor; VALUE_PAIR *vp; fr_assert(client->dynamic); diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 3371b699f2a..21819163b7b 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -1184,6 +1184,7 @@ static decode_fail_t decode(TALLOC_CTX *ctx, VALUE_PAIR **reply, uint8_t *respon decode_fail_t reason; uint8_t code; uint8_t original[RADIUS_HEADER_LENGTH]; + fr_cursor_t cursor; *response_code = 0; /* Initialise to keep the rest of the code happy */ @@ -1238,8 +1239,9 @@ static decode_fail_t decode(TALLOC_CTX *ctx, VALUE_PAIR **reply, uint8_t *respon * This only fails if the packet is strangely malformed, * or if we run out of memory. */ + fr_cursor_init(&cursor, reply); if (fr_radius_decode(ctx, data, packet_len, original, - inst->secret, talloc_array_length(inst->secret) - 1, reply) < 0) { + inst->secret, talloc_array_length(inst->secret) - 1, &cursor) < 0) { REDEBUG("Failed decoding attributes for packet"); fr_pair_list_free(reply); return DECODE_FAIL_UNKNOWN; diff --git a/src/protocols/radius/base.c b/src/protocols/radius/base.c index 607ec119910..51a50c8cb09 100644 --- a/src/protocols/radius/base.c +++ b/src/protocols/radius/base.c @@ -1080,10 +1080,9 @@ ssize_t fr_radius_encode(uint8_t *packet, size_t packet_len, uint8_t const *orig * */ ssize_t fr_radius_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len, uint8_t const *original, - char const *secret, UNUSED size_t secret_len, VALUE_PAIR **vps) + char const *secret, UNUSED size_t secret_len, fr_cursor_t *cursor) { ssize_t slen; - fr_cursor_t cursor; uint8_t const *attr, *end; fr_radius_ctx_t packet_ctx; @@ -1091,8 +1090,6 @@ ssize_t fr_radius_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l packet_ctx.secret = secret; packet_ctx.vector = original ? original + 4 : packet + 4; - fr_cursor_init(&cursor, vps); - attr = packet + 20; end = packet + packet_len; @@ -1101,7 +1098,7 @@ ssize_t fr_radius_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l * he doesn't, all hell breaks loose. */ while (attr < end) { - slen = fr_radius_decode_pair(ctx, &cursor, dict_radius, attr, (end - attr), &packet_ctx); + slen = fr_radius_decode_pair(ctx, cursor, dict_radius, attr, (end - attr), &packet_ctx); if (slen < 0) { talloc_free(packet_ctx.tmp_ctx); return slen; diff --git a/src/protocols/radius/decode.c b/src/protocols/radius/decode.c index f0c982fb7be..aa368246b81 100644 --- a/src/protocols/radius/decode.c +++ b/src/protocols/radius/decode.c @@ -1763,7 +1763,7 @@ static ssize_t fr_radius_decode_proto(TALLOC_CTX *ctx, VALUE_PAIR **vps, uint8_t vp = fr_cursor_tail(&cursor); return fr_radius_decode(ctx, data, packet_len, test_ctx->vector - 4, /* decode adds 4 to this */ - test_ctx->secret, talloc_array_length(test_ctx->secret) - 1, &vp->next); + test_ctx->secret, talloc_array_length(test_ctx->secret) - 1, &cursor); } /* diff --git a/src/protocols/radius/radius.h b/src/protocols/radius/radius.h index 79f61d1cac6..2e52c6693cb 100644 --- a/src/protocols/radius/radius.h +++ b/src/protocols/radius/radius.h @@ -128,7 +128,7 @@ ssize_t fr_radius_encode(uint8_t *packet, size_t packet_len, uint8_t const *ori char const *secret, UNUSED size_t secret_len, int code, int id, VALUE_PAIR *vps); ssize_t fr_radius_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len, uint8_t const *original, - char const *secret, UNUSED size_t secret_len, VALUE_PAIR **vps) CC_HINT(nonnull(1,2,5,7)); + char const *secret, UNUSED size_t secret_len, fr_cursor_t *cursor) CC_HINT(nonnull(1,2,5,7)); int fr_radius_init(void);