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.
* 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;
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;