]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Add const to hashable_roa.data
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 31 Jan 2023 23:58:52 +0000 (17:58 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 31 Jan 2023 23:58:52 +0000 (17:58 -0600)
Not a fix, but it proves that the protocol never purposefully changes
outside of the ROA's constructors.

So I guess the options are... it's either inadvertently changing,
or the foreach is iterating into unrelated memory.

src/rtr/db/db_table.c

index a0b85705b8c167705c4d4e56b2088126a1f82045..5ebf24beee7ddbc13c5674b1169232e20903db83 100644 (file)
@@ -7,7 +7,7 @@
 #include "data_structure/uthash_nonfatal.h"
 
 struct hashable_roa {
-       struct vrp data;
+       const struct vrp data;
        UT_hash_handle hh;
 };
 
@@ -87,29 +87,18 @@ db_table_foreach_router_key(struct db_table const *table,
        return 0;
 }
 
-static struct hashable_roa *
-create_roa(uint32_t asn, uint8_t max_length)
-{
-       struct hashable_roa *roa;
-
-       roa = malloc(sizeof(struct hashable_roa));
-       if (roa == NULL)
-               return NULL;
-       /* Needed by uthash */
-       memset(roa, 0, sizeof(struct hashable_roa));
-
-       roa->data.asn = asn;
-       roa->data.max_prefix_length = max_length;
-
-       return roa;
-}
-
 static int
-add_roa(struct db_table *table, struct hashable_roa *new)
+add_roa(struct db_table *table, struct hashable_roa const *stack_new)
 {
+       struct hashable_roa *new;
        struct hashable_roa *old;
        int error;
 
+       new = malloc(sizeof(struct hashable_roa));
+       if (new == NULL)
+               return pr_enomem();
+       memcpy(new, stack_new, sizeof(*new));
+
        errno = 0;
        HASH_REPLACE(hh, table->roas, data, sizeof(new->data), new, old);
        error = errno;
@@ -185,40 +174,30 @@ int
 rtrhandler_handle_roa_v4(struct db_table *table, uint32_t asn,
     struct ipv4_prefix const *prefix4, uint8_t max_length)
 {
-       struct hashable_roa *roa;
-       int error;
-
-       roa = create_roa(asn, max_length);
-       if (roa == NULL)
-               return pr_enomem();
-       roa->data.prefix.v4 = prefix4->addr;
-       roa->data.prefix_length = prefix4->len;
-       roa->data.addr_fam = AF_INET;
-
-       error = add_roa(table, roa);
-       if (error)
-               free(roa);
-       return error;
+       struct hashable_roa new = {
+               .data.asn = asn,
+               .data.prefix.v4 = prefix4->addr,
+               .data.prefix_length = prefix4->len,
+               .data.max_prefix_length = max_length,
+               .data.addr_fam = AF_INET,
+       };
+
+       return add_roa(table, &new);
 }
 
 int
 rtrhandler_handle_roa_v6(struct db_table *table, uint32_t asn,
     struct ipv6_prefix const *prefix6, uint8_t max_length)
 {
-       struct hashable_roa *roa;
-       int error;
-
-       roa = create_roa(asn, max_length);
-       if (roa == NULL)
-               return pr_enomem();
-       roa->data.prefix.v6 = prefix6->addr;
-       roa->data.prefix_length = prefix6->len;
-       roa->data.addr_fam = AF_INET6;
-
-       error = add_roa(table, roa);
-       if (error)
-               free(roa);
-       return error;
+       struct hashable_roa new = {
+               .data.asn = asn,
+               .data.prefix.v6 = prefix6->addr,
+               .data.prefix_length = prefix6->len,
+               .data.max_prefix_length = max_length,
+               .data.addr_fam = AF_INET6,
+       };
+
+       return add_roa(table, &new);
 }
 
 int