]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
DHCPv4: Still need to copy pairs to a local list so we can search for options
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 27 Jan 2021 18:56:40 +0000 (18:56 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 27 Jan 2021 18:56:46 +0000 (18:56 +0000)
src/protocols/dhcpv4/packet.c

index f3ec4bd36a5ef9a3d98667d8b537b416689af5d7..462339c793a13de8630fbae562980c98d511d3ca 100644 (file)
@@ -112,8 +112,11 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
        fr_pair_t       *vp;
        fr_pair_t       *maxms, *mtu, *netaddr;
        fr_value_box_t  box;
+       fr_dcursor_t    our_cursor;
 
        fr_pair_list_init(&head);
+       fr_dcursor_init(&our_cursor, &head);
+
        if (data[1] > 1) {
                fr_strerror_printf("Packet is not Ethernet: %u",
                      data[1]);
@@ -131,8 +134,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                        fr_strerror_const_push("Cannot decode packet due to internal error");
                error:
                        talloc_free(vp);
-                       fr_dcursor_head(cursor);
-                       fr_dcursor_free_list(cursor);
+                       fr_dcursor_head(&our_cursor);
+                       fr_dcursor_free_list(&our_cursor);
                        return -1;
                }
 
@@ -190,14 +193,14 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
 
                if (!vp) continue;
 
-               fr_dcursor_append(cursor, vp);
+               fr_dcursor_append(&our_cursor, vp);
        }
 
        /*
         *      Loop over the options.
         */
 
-       fr_dcursor_head(cursor);
+       fr_dcursor_head(&our_cursor);
 
        /*
         *      Nothing uses tail after this call, if it does in the future
@@ -216,10 +219,10 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                while (p < end) {
                        if (p[0] == 0) break; /* padding */
 
-                       len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4, p, (end - p), NULL);
+                       len = fr_dhcpv4_decode_option(ctx, &our_cursor, dict_dhcpv4, p, (end - p), NULL);
                        if (len <= 0) {
-                               fr_dcursor_head(cursor);
-                               fr_dcursor_free_list(cursor);
+                               fr_dcursor_head(&our_cursor);
+                               fr_dcursor_free_list(&our_cursor);
                                return len;
                        }
                        p += len;
@@ -248,11 +251,11 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                                while (p < end) {
                                        if (p[0] == 0) break; /* padding */
 
-                                       len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4,
+                                       len = fr_dhcpv4_decode_option(ctx, &our_cursor, dict_dhcpv4,
                                                                      p, end - p, NULL);
                                        if (len <= 0) {
-                                               fr_dcursor_head(cursor);
-                                               fr_dcursor_free_list(cursor);
+                                               fr_dcursor_head(&our_cursor);
+                                               fr_dcursor_free_list(&our_cursor);
                                                return len;
                                        }
                                        p += len;
@@ -271,8 +274,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                                        len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4,
                                                                      p, end - p, NULL);
                                        if (len <= 0) {
-                                               fr_dcursor_head(cursor);
-                                               fr_dcursor_free_list(cursor);
+                                               fr_dcursor_head(&our_cursor);
+                                               fr_dcursor_free_list(&our_cursor);
                                                return len;
                                        }
                                        p += len;
@@ -360,7 +363,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, &box);
        }
 
-       fr_dcursor_append(cursor, vp);
+       fr_dcursor_append(&our_cursor, vp);
 
        /*
         *      Client can request a LARGER size, but not a smaller
@@ -389,6 +392,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
         *      FIXME: Nuke attributes that aren't used in the normal
         *      header for discover/requests.
         */
+       fr_dcursor_merge(cursor, &our_cursor);
 
        return 0;
 }