From 5622c45df4019bf6305a0aebe6b306c667f0391c Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 10 Sep 2020 19:08:49 +0200 Subject: [PATCH] MINOR: ssl: crtlist_entry_dup() duplicates a crtlist_entry Implement crtlist_entry_dup() which allocate and duplicate a crtlist_entry structure. --- src/ssl_crtlist.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/ssl_crtlist.c b/src/ssl_crtlist.c index d70e2ab91..393f4ea42 100644 --- a/src/ssl_crtlist.c +++ b/src/ssl_crtlist.c @@ -196,6 +196,45 @@ void crtlist_entry_free(struct crtlist_entry *entry) } free(entry); } +/* + * Duplicate a crt_list entry and its content (ssl_conf, filters/fcount) + * Return a pointer to the new entry + */ +struct crtlist_entry *crtlist_entry_dup(struct crtlist_entry *src) +{ + struct crtlist_entry *entry; + + if (src == NULL) + return NULL; + + entry = crtlist_entry_new(); + if (entry == NULL) + return NULL; + + if (src->filters) { + entry->filters = crtlist_dup_filters(src->filters, src->fcount); + if (!entry->filters) + goto error; + } + entry->fcount = src->fcount; + if (src->ssl_conf) { + entry->ssl_conf = crtlist_dup_ssl_conf(src->ssl_conf); + if (!entry->ssl_conf) + goto error; + } + entry->crtlist = src->crtlist; + + return entry; + +error: + + crtlist_free_filters(entry->filters); + ssl_sock_free_ssl_conf(entry->ssl_conf); + free(entry->ssl_conf); + free(entry); + + return NULL; +} /* * Allocate and initialize a crtlist_entry