From: Remi Tricot-Le Breton Date: Thu, 26 Nov 2026 10:11:54 +0000 (+0100) Subject: BUG/MINOR: jwt: Do not keep ckch_store if jwt tree entry creation failed X-Git-Url: https://git.kaiwu.me/http/%22../static/gitweb.js?a=commitdiff_plain;h=825e018da29eaf27a378ab117a79b377f4466c20;p=haproxy.git BUG/MINOR: jwt: Do not keep ckch_store if jwt tree entry creation failed When a full certificate is provided directly as a second argument of the "jwt_verify_cert" converter, we create the corresponding ckch_store and insert it in the ckch_store tree so that it's treated as a regular certificate. This helps in certificate management since that way the certificate can be updated via the CLI. With the latest changes in the JWT tree, we now always have a corresponding JWT tree entry for every ckch_store, regardless of whether they set the jwt flag or not. And in every other part of the ckch_store building process apart the one modified in this patch, we were raising an error and removing the new ckch_store if an error occurred during the corresponding JWT tree entry creation. This patch keeps this logic in the 'jwt_tree_load_cert' function as well. This patch can be backported to 3.4. --- diff --git a/src/jwt.c b/src/jwt.c index ed70c5bd2..78576a1a7 100644 --- a/src/jwt.c +++ b/src/jwt.c @@ -432,16 +432,32 @@ int jwt_tree_load_cert(char *path, int pathlen, const char *file, int line, char goto end; } + store->conf.jwt = 1; + retval = jwt_tree_create_entry_from_store(store, err); + if (retval) { + /* Something went wrong during the JWT tree entry + * creation, likely an OOM, no point in inserting the + * ckch_store in the tree if we cannot use it for JWT + * validation. */ + ckch_store_free(store); + HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock); + goto end; + } + if (ebst_insert(&ckchs_tree, &store->node) != &store->node) { + /* The ckch_store was not inserted in the tree so the + * corresponding jwt tree entry would not be removed in + * ckch_store_free. */ + jwt_tree_delete_entry(store->path); ckch_store_free(store); HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock); goto end; } + } else { + store->conf.jwt = 1; + retval = jwt_tree_create_entry_from_store(store, err); } - store->conf.jwt = 1; - - retval = jwt_tree_create_entry_from_store(store, err); HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);