]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: http/hardening: free the new profile on strdup() failure
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 17 Nov 2026 10:14:57 +0000 (11:14 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 17 Nov 2026 10:39:49 +0000 (11:39 +0100)
In cfg_parse_http_hardening(), when strdup() of the file name fails after
a new profile was allocated by http_hardening_new(), the profile is not
yet indexed and its only reference is lost on "goto out", leaking it and
its name. Let's release it with http_hardening_free(), which is safe for
the static profiles.

This was reported by Coverity (CID 1690184) in GitHub issue #3560, with
the analysis and fix provided by Alexandre Laroche. It was introduced by
commit fa70a47cb ("MINOR: cfgparse/http: add a simple parser for new
section "http-fingerprint"") in 3.5-dev11, so no backport is needed.

src/http.c

index 6327b1713994cd06847769d56f458c5a18c9f091..7701a8b5dfc84948043823a7263d7106e49041a3 100644 (file)
@@ -1889,6 +1889,8 @@ struct http_hdng_prf *http_hardening_resolve(const char *name, char **err)
  * hardening option is followed by "on" or "off" to enable or disable the
  * matching checks.
  */
+static void http_hardening_free(struct http_hdng_prf *prf);
+
 int cfg_parse_http_hardening(const char *file, int linenum, char **args, int kwm)
 {
        struct http_hdng_prf *prf, *other, *base = NULL;
@@ -1973,6 +1975,7 @@ int cfg_parse_http_hardening(const char *file, int linenum, char **args, int kwm
                if (!file_copy) {
                        ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        err_code |= ERR_ALERT | ERR_ABORT;
+                       http_hardening_free(prf);
                        goto out;
                }
                prf->file = file_copy;