]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: ssl/cli: restore the store conf on "add ssl crt-list" error
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 25 Nov 2026 16:47:42 +0000 (17:47 +0100)
committerOlivier Houchard <cognet@ci0.org>
Wed, 25 Nov 2026 16:37:36 +0000 (17:37 +0100)
In cli_parse_add_crtlist(), a store without any instance adopts the
ckch_conf parsed from the line, but if the line is rejected afterwards,
the error path frees the content of that conf, and the store keeps
pointers to freed strings. They are then printed by "show ssl cert" and
freed again by "del ssl cert". It can be triggered by adding a
certificate created with "new ssl cert" to a crt-list which is a
directory, using crt-store keywords such as "key" or "issuer".

Let's save the previous conf of the store and restore it on error, so
that a rejected line doesn't change the store. This was introduced by
commit 1bc6e990f ("MEDIUM: ssl/cli: handle crt-store keywords in crt-list
over the CLI") in 3.0-dev12, so this should be backported to 3.0.

src/ssl_crtlist.c

index 494b5ea23e3312b5a96e5eb7ffd30c1f8d870c5e..a3fb796188df92a586f789e244bd29b42e0822b7 100644 (file)
@@ -1343,6 +1343,8 @@ static int cli_parse_add_crtlist(char **args, char *payload, struct appctx *appc
        struct crtlist *crtlist;
        struct crtlist_entry *entry = NULL;
        struct ckch_conf cc = {};
+       struct ckch_conf old_cc = {};
+       int adopted = 0;
        char *end;
 
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
@@ -1422,7 +1424,9 @@ static int cli_parse_add_crtlist(char **args, char *payload, struct appctx *appc
         */
        if (LIST_ISEMPTY(&store->ckch_inst)) {
 
+               old_cc = store->conf;
                store->conf = cc;
+               adopted = 1;
                /* fresh new, run more init (for example init ocsp-update tasks) */
                cfgerr |= ckch_store_load_files(&cc, store, 1, "CLI", 1, &err);
                if (cfgerr & ERR_FATAL)
@@ -1460,6 +1464,9 @@ static int cli_parse_add_crtlist(char **args, char *payload, struct appctx *appc
        return 0;
 
 error:
+       /* the store must not keep the conf freed below */
+       if (adopted)
+               store->conf = old_cc;
        ckch_conf_clean(&cc);
        crtlist_entry_free(entry);
        HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);