]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
pass non-NULL decode ctx to decode option function
authorAlan T. DeKok <aland@freeradius.org>
Sat, 12 Mar 2022 15:04:51 +0000 (10:04 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 12 Mar 2022 15:04:51 +0000 (10:04 -0500)
src/protocols/dhcpv4/dhcpv4.h
src/protocols/dhcpv4/packet.c

index 23e2ef51be34bc02c9863c974e1920974a23b541..d2b3f7e0ece6c5009fae151dda2d2f0d3ccad915 100644 (file)
@@ -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
index 150b0d7ed8b8aadead303b4dd398f331072806a5..651df4f621ee83f8e03ae8811d4d35e866925b80 100644 (file)
@@ -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);