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.
This commit is contained in:
Willy Tarreau 2023-11-13 09:17:05 +01:00
parent 79aa638238
commit cf07cb96be
4 changed files with 3 additions and 7 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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 <defproxy>. */
@ -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;