From cf07cb96be70cbe979c6cf21aefd134894cf743f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 13 Nov 2023 09:17:05 +0100 Subject: [PATCH] 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. --- src/cfgparse-listen.c | 1 - src/hlua.c | 1 - src/http_client.c | 2 -- src/proxy.c | 6 +++--- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 6c7cc6382..70820bab4 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 c5a1c615b..d1b28b939 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 fca13a297..3e761b81a 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 544c22f82..f1b81f6f8 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;