]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix fr_dhcpv4_decode_option to return the correct values
authorAlan T. DeKok <aland@freeradius.org>
Tue, 15 Mar 2022 13:42:10 +0000 (09:42 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 15 Mar 2022 13:42:10 +0000 (09:42 -0400)
we don't return the length of the decoded data, we return
however much we decoded in one option.

src/protocols/dhcpv4/decode.c
src/protocols/dhcpv4/encode.c

index d639111f3a54b425839ddd36d57fb4594304988e..71e9376d074f505be25f906489b94d1f29c664d7 100644 (file)
@@ -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)
index c907e4051ae85637ae63e10bf7f806396363237f..e370432358eb72cff105ca106335cc02e1e4fc75 100644 (file)
@@ -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);