From: Alan T. DeKok Date: Sat, 12 Mar 2022 15:04:51 +0000 (-0500) Subject: pass non-NULL decode ctx to decode option function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0911ac7f59acda9772c86848d66b119686af8a9f;p=thirdparty%2Ffreeradius-server.git pass non-NULL decode ctx to decode option function --- diff --git a/src/protocols/dhcpv4/dhcpv4.h b/src/protocols/dhcpv4/dhcpv4.h index 23e2ef51be3..d2b3f7e0ece 100644 --- a/src/protocols/dhcpv4/dhcpv4.h +++ b/src/protocols/dhcpv4/dhcpv4.h @@ -142,6 +142,7 @@ extern HIDDEN fr_dict_attr_t const *dhcp_option_82; */ typedef struct { fr_dict_attr_t const *root; + uint8_t *buffer; //! for coalescing concatenated options } fr_dhcpv4_ctx_t; /* @@ -162,7 +163,7 @@ void fr_dhcpv4_print_hex(FILE *fp, uint8_t const *packet, size_t packet_len); * decode.c */ ssize_t fr_dhcpv4_decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, - uint8_t const *data, size_t len, void *decode_ctx); + uint8_t const *data, size_t len, void *decode_ctx) CC_HINT(nonnull); /* * encode.c diff --git a/src/protocols/dhcpv4/packet.c b/src/protocols/dhcpv4/packet.c index 150b0d7ed8b..651df4f621e 100644 --- a/src/protocols/dhcpv4/packet.c +++ b/src/protocols/dhcpv4/packet.c @@ -106,6 +106,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, fr_pair_t *vp; fr_pair_t *maxms, *mtu, *netaddr; fr_value_box_t box; + fr_dhcpv4_ctx_t *packet_ctx; fr_pair_list_init(&tmp); @@ -115,6 +116,9 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, return -1; } + packet_ctx = talloc_zero(ctx, fr_dhcpv4_ctx_t); + if (!packet_ctx) return -1; + /* * Decode the header. */ @@ -127,6 +131,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, error: talloc_free(vp); fr_pair_list_free(&tmp); + talloc_free(packet_ctx); return -1; } @@ -205,9 +210,11 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, while (p < end) { if (p[0] == 0) break; /* padding */ - len = fr_dhcpv4_decode_option(ctx, &tmp, p, (end - p), NULL); + len = fr_dhcpv4_decode_option(ctx, &tmp, p, (end - p), packet_ctx); if (len <= 0) { + fail: fr_pair_list_free(&tmp); + talloc_free(packet_ctx); return len; } p += len; @@ -237,11 +244,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, if (p[0] == 0) break; /* padding */ len = fr_dhcpv4_decode_option(ctx, &tmp, - p, end - p, NULL); - if (len <= 0) { - fr_pair_list_free(&tmp); - return len; - } + p, end - p, packet_ctx); + if (len <= 0) goto fail; p += len; } fr_pair_delete_by_da(&tmp, attr_dhcp_boot_filename); @@ -256,11 +260,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, if (p[0] == 0) break; /* padding */ len = fr_dhcpv4_decode_option(ctx, &tmp, - p, end - p, NULL); - if (len <= 0) { - fr_pair_list_free(&tmp); - return len; - } + p, end - p, packet_ctx); + if (len <= 0) goto fail; p += len; } fr_pair_delete_by_da(&tmp, attr_dhcp_server_host_name);