From: William Lallemand Date: Fri, 11 Apr 2025 21:46:22 +0000 (+0200) Subject: MINOR: ssl/ckch: handle ckch_conf in ckchs_dup() and ckch_conf_clean() X-Git-Tag: v3.2-dev11~83 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b85b81d841096516a6104d0df2c6ca629fb5295;p=thirdparty%2Fhaproxy.git MINOR: ssl/ckch: handle ckch_conf in ckchs_dup() and ckch_conf_clean() Handle new members of the ckch_conf in ckchs_dup() and ckch_conf_clean(). This could be automated at some point since we have the description of all types in ckch_conf_kws. --- diff --git a/src/ssl_ckch.c b/src/ssl_ckch.c index 8056cf0cf..747ee4cca 100644 --- a/src/ssl_ckch.c +++ b/src/ssl_ckch.c @@ -1027,6 +1027,8 @@ error: struct ckch_store *ckchs_dup(const struct ckch_store *src) { struct ckch_store *dst; + int n = 0; + char **r = NULL; if (!src) return NULL; @@ -1041,9 +1043,50 @@ struct ckch_store *ckchs_dup(const struct ckch_store *src) dst->conf.ocsp_update_mode = src->conf.ocsp_update_mode; + /* copy ckch_conf + * XXX: could be automated for each fiedl with the + * ckch_conf array used for parsing */ + + if (src->conf.crt) + dst->conf.crt = strdup(src->conf.crt); + if (src->conf.key) + dst->conf.key = strdup(src->conf.key); + if (src->conf.ocsp) + dst->conf.ocsp = strdup(src->conf.ocsp); + if (src->conf.issuer) + dst->conf.issuer = strdup(src->conf.issuer); + if (src->conf.sctl) + dst->conf.sctl = strdup(src->conf.sctl); + if (src->conf.acme.id) + dst->conf.acme.id = strdup(src->conf.acme.id); + if (src->conf.acme.domains) { + + /* copy the array of domain strings */ + + while (src->conf.acme.domains[n]) { + r = realloc(r, sizeof(char *) * (n + 2)); + if (!r) + goto error; + + r[n] = strdup(src->conf.acme.domains[n]); + if (!r[n]) { + goto error; + } + n++; + } + r[n] = 0; + dst->conf.acme.domains = r; + } + return dst; error: + while (r && *r) { + char *prev = *r; + r++; + free(prev); + } + free(r); ckch_store_free(dst); return NULL; @@ -4895,14 +4938,27 @@ out: /* freeing the content of a ckch_conf structure */ void ckch_conf_clean(struct ckch_conf *conf) { + char **r; + if (!conf) return; - free(conf->crt); - free(conf->key); - free(conf->ocsp); - free(conf->issuer); - free(conf->sctl); + ha_free(&conf->crt); + ha_free(&conf->key); + ha_free(&conf->ocsp); + ha_free(&conf->issuer); + ha_free(&conf->sctl); + + ha_free(&conf->acme.id); + + r = conf->acme.domains; + while (r && *r) { + char *prev = *r; + r++; + free(prev); + } + ha_free(&conf->acme.domains); + } static char current_crtstore_name[PATH_MAX] = {};