From: Willy Tarreau Date: Mon, 13 Nov 2023 08:17:05 +0000 (+0100) Subject: BUG/MEDIUM: proxy: always initialize the default settings after init X-Git-Tag: v2.9-dev10~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf07cb96be70cbe979c6cf21aefd134894cf743f;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: proxy: always initialize the default settings after init The proxy's initialization is rather odd. First, init_new_proxy() is called to zero all the lists and certain values, except those that can come from defaults, which are initialized by proxy_preset_defaults(). The default server settings are also only set there. This results in these settings not to be set for a number of internal proxies that do not explicitly call proxy_preset_defaults() after allocation, such as sink and log forwarders. This was revealed by last commit 79aa63823 ("MINOR: server: always initialize pp_tlvs for default servers") which crashes in log parsers when applied to certain proxies which did not initialize their default servers. In theory this should be backported, however it would be desirable to wait a bit before backporting it, in case certain parts would rely on these elements not being initialized. --- diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 6c7cc6382a..70820bab49 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -213,7 +213,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) if (!last_defproxy) { /* we need a default proxy and none was created yet */ last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, &errmsg); - proxy_preset_defaults(last_defproxy); curr_defproxy = last_defproxy; if (!last_defproxy) { diff --git a/src/hlua.c b/src/hlua.c index c5a1c615bd..d1b28b939b 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -13877,7 +13877,6 @@ void hlua_init(void) { fprintf(stderr, "Lua init: %s\n", errmsg); exit(1); } - proxy_preset_defaults(socket_proxy); /* Init TCP server: unchanged parameters */ socket_tcp = new_server(socket_proxy); diff --git a/src/http_client.c b/src/http_client.c index fca13a2976..3e761b81af 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -1213,8 +1213,6 @@ struct proxy *httpclient_create_proxy(const char *id) goto err; } - proxy_preset_defaults(px); - px->options |= PR_O_WREQ_BODY; px->retry_type |= PR_RE_CONN_FAILED | PR_RE_DISCONNECTED | PR_RE_TIMEOUT; px->options2 |= PR_O2_INDEPSTR; diff --git a/src/proxy.c b/src/proxy.c index 544c22f826..f1b81f6f8a 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1430,6 +1430,9 @@ void init_new_proxy(struct proxy *p) p->extra_counters_be = NULL; HA_RWLOCK_INIT(&p->lock); + + /* initialize the default settings */ + proxy_preset_defaults(p); } /* Preset default settings onto proxy . */ @@ -1946,9 +1949,6 @@ struct proxy *parse_new_proxy(const char *name, unsigned int cap, return NULL; } } - else { - proxy_preset_defaults(curproxy); - } curproxy->conf.args.file = curproxy->conf.file = strdup(file); curproxy->conf.args.line = curproxy->conf.line = linenum;