From 91176c18e4e72698f533a6e40022f336f75e399e Mon Sep 17 00:00:00 2001 From: job Date: Sat, 3 Sep 2022 21:24:02 +0000 Subject: [PATCH] Properly free() crl & auth tree in parser process OK claudio@ --- usr.sbin/rpki-client/cert.c | 14 +++++++++++++- usr.sbin/rpki-client/crl.c | 13 ++++++++++++- usr.sbin/rpki-client/extern.h | 4 +++- usr.sbin/rpki-client/parser.c | 7 +++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/usr.sbin/rpki-client/cert.c b/usr.sbin/rpki-client/cert.c index 76ceca7a0d3..0098c0eb0b6 100644 --- a/usr.sbin/rpki-client/cert.c +++ b/usr.sbin/rpki-client/cert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cert.c,v 1.88 2022/09/03 14:40:09 job Exp $ */ +/* $OpenBSD: cert.c,v 1.89 2022/09/03 21:24:02 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2021 Job Snijders @@ -978,6 +978,18 @@ authcmp(struct auth *a, struct auth *b) RB_GENERATE_STATIC(auth_tree, auth, entry, authcmp); +void +auth_tree_free(struct auth_tree *auths) +{ + struct auth *auth, *tauth; + + RB_FOREACH_SAFE(auth, auth_tree, auths, tauth) { + RB_REMOVE(auth_tree, auths, auth); + cert_free(auth->cert); + free(auth); + } +} + struct auth * auth_find(struct auth_tree *auths, const char *aki) { diff --git a/usr.sbin/rpki-client/crl.c b/usr.sbin/rpki-client/crl.c index 749f23c7d8d..25bb2b56556 100644 --- a/usr.sbin/rpki-client/crl.c +++ b/usr.sbin/rpki-client/crl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crl.c,v 1.15 2022/04/21 09:53:07 claudio Exp $ */ +/* $OpenBSD: crl.c,v 1.16 2022/09/03 21:24:02 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -118,3 +118,14 @@ crl_free(struct crl *crl) X509_CRL_free(crl->x509_crl); free(crl); } + +void +crl_tree_free(struct crl_tree *crlt) +{ + struct crl *crl, *tcrl; + + RB_FOREACH_SAFE(crl, crl_tree, crlt, tcrl) { + RB_REMOVE(crl_tree, crlt, crl); + crl_free(crl); + } +} diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 43ebfcc35bd..77eee1dc97b 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.155 2022/09/03 14:40:09 job Exp $ */ +/* $OpenBSD: extern.h,v 1.156 2022/09/03 21:24:02 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -511,6 +511,7 @@ struct tal *tal_read(struct ibuf *); void cert_buffer(struct ibuf *, const struct cert *); void cert_free(struct cert *); +void auth_tree_free(struct auth_tree *); struct cert *cert_parse_ee_cert(const char *, X509 *); struct cert *cert_parse_pre(const char *, const unsigned char *, size_t); struct cert *cert_parse(const char *, struct cert *); @@ -556,6 +557,7 @@ struct crl *crl_parse(const char *, const unsigned char *, size_t); struct crl *crl_get(struct crl_tree *, const struct auth *); int crl_insert(struct crl_tree *, struct crl *); void crl_free(struct crl *); +void crl_tree_free(struct crl_tree *); /* Validation of our objects. */ diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index cf8e7b0e364..a6139669251 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.76 2022/09/03 13:30:27 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.77 2022/09/03 21:24:02 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -744,10 +744,13 @@ proc_parser(int fd) entity_free(entp); } - /* XXX free auths and crl tree */ + auth_tree_free(&auths); + crl_tree_free(&crlt); X509_STORE_CTX_free(ctx); msgbuf_clear(&msgq); + ibuf_free(inbuf); + exit(0); } -- 2.20.1