From: Alan T. DeKok Date: Tue, 15 Mar 2022 13:42:10 +0000 (-0400) Subject: fix fr_dhcpv4_decode_option to return the correct values X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1de1257162126c8b9fbf6ffd4db8212dc8fcf628;p=thirdparty%2Ffreeradius-server.git fix fr_dhcpv4_decode_option to return the correct values we don't return the length of the decoded data, we return however much we decoded in one option. --- diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index d639111f3a5..71e9376d074 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -500,7 +500,6 @@ static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, option = data[0]; len = data[1]; if (len > (data_len - 2)) { - fprintf(stderr, "FAIL %d\n", __LINE__); fr_strerror_printf("%s: Option overflows input. " "Optional length must be less than %zu bytes, got %zu bytes", __FUNCTION__, data_len - 2, len); @@ -661,18 +660,15 @@ ssize_t fr_dhcpv4_decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, /* * The actual amount of data we decoded, including the various headers. */ - slen = next - data; - goto done; + FR_PROTO_TRACE("decoding option complete, %zu decoded, returning %zu byte(s)", slen, (size_t) (next - data)); + return next - data; } slen = decode_option(ctx, out, fr_dict_root(dict_dhcpv4), data, data[1] + 2, decode_ctx); - if (slen < 0) { - return slen; - } + if (slen < 0) return slen; -done: - FR_PROTO_TRACE("decoding option complete, returning %zu byte(s)", slen); - return slen; + FR_PROTO_TRACE("decoding option complete, %zu decoded, returning %u byte(s)", slen, data[1] + 2); + return data[1] + 2; } static int _decode_test_ctx(UNUSED fr_dhcpv4_ctx_t *test_ctx) diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index c907e4051ae..e370432358e 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -90,7 +90,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, FR_PROTO_TRACE("%zu byte(s) available for value", fr_dbuff_remaining(dbuff)); /* - * Pack multiple attributes into into a single option + * Structures are special. */ if ((vp->da->type == FR_TYPE_STRUCT) || (da->type == FR_TYPE_STRUCT)) { slen = fr_struct_to_network(&work_dbuff, da_stack, depth, cursor, encode_ctx, encode_value_trampoline, encode_tlv);