]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix memory leaks
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 24 Oct 2025 22:05:50 +0000 (16:05 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 24 Oct 2025 22:05:50 +0000 (16:05 -0600)
src/asn1/asn1c/INTEGER.c
src/asn1/asn1c/INTEGER.h
src/cache.c
src/rrdp.c

index 01e5202ec5f5616f4393286c1aaf4dded663d930..9fc43a80df3e03b8a7c4a1a097b0a9b64175fff0 100644 (file)
@@ -790,6 +790,30 @@ INTEGER_move(INTEGER_t *to, INTEGER_t *from)
        memset(from, 0, sizeof(*from));
 }
 
+void
+INTEGER_copy(INTEGER_t *to, INTEGER_t *from)
+{
+       to->size = from->size;
+       to->buf = pmalloc(to->size);
+       memcpy(to->buf, from->buf, to->size);
+}
+
+static int
+just_print(const void *buffer, size_t size, void *pfx)
+{
+       pr_trc("%s: %.*s", (char const *)pfx, (int)size, buffer);
+       return 0;
+}
+
+void
+INTEGER_trc(char const *pfx, INTEGER_t *st)
+{
+       if (st != NULL)
+               INTEGER_print(&asn_DEF_INTEGER, st, 2, just_print, (void *)pfx);
+       else
+               pr_trc("%s: NULL", pfx);
+}
+
 void
 INTEGER_cleanup(INTEGER_t *st)
 {
index 68e9027c4cb53e6b2b9eabc1b5aa00830d346614..a85ec1c7e7d8299989cea79444f4d9597afff369 100644 (file)
@@ -93,6 +93,8 @@ const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(
 
 int INTEGER_cmp(INTEGER_t const *, INTEGER_t const *);
 void INTEGER_move(INTEGER_t *, INTEGER_t *);
+void INTEGER_copy(INTEGER_t *, INTEGER_t *);
+void INTEGER_trc(char const *, INTEGER_t *);
 void INTEGER_cleanup(INTEGER_t *);
 
 #endif /* _INTEGER_H_ */
index 34f5e68b0dc7540c2959367ca21c87427b23771c..bcd6d76c96c9aa130d0dd6ca1e4980b83fd2154a 100644 (file)
@@ -1305,6 +1305,7 @@ commit_rpp(struct cache_commit *commit, struct cache_node *fb)
        char const *dst;
        array_index i;
 
+       INTEGER_cleanup(&fb->mft.num);
        INTEGER_move(&fb->mft.num, &commit->mft.num);
        fb->mft.update = commit->mft.update;
 
index 52ca117c83e1dc699dd44a7bb151bcddbd3d0233..e6b39577ee12ca7b2fbd9c333bc02ee9ab80fe0a 100644 (file)
@@ -1148,9 +1148,11 @@ update_notif(struct rrdp_state *old, struct update_notification *new)
        struct rrdp_hash *hash;
 
        diff_bn = BN_create();
-       if (!BN_sub(diff_bn, new->session.serial.num, old->session.serial.num))
+       if (!BN_sub(diff_bn, new->session.serial.num, old->session.serial.num)) {
+               BN_free(diff_bn);
                return pr_crypto_err("OUCH! libcrypto cannot subtract %s - %s",
                    new->session.serial.str, old->session.serial.str);
+       }
        if (BN_is_negative(diff_bn))
                /* The validation was the BN_cmp() in the caller. */
                pr_panic("%s - %s < 0 despite validations.",
@@ -1161,6 +1163,7 @@ update_notif(struct rrdp_state *old, struct update_notification *new)
                /* Should be <= because it was already compared to the delta threshold. */
                pr_panic("%lu > %zu despite validations.",
                    diff, new->deltas.len);
+       BN_free(diff_bn);
 
        BN_free(old->session.serial.num);
        free(old->session.serial.str);