From: Willy Tarreau Date: Thu, 4 Oct 2012 06:01:43 +0000 (+0200) Subject: BUG/MINOR: config: use a copy of the file name in proxy configurations X-Git-Tag: v1.5-dev13~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8113a5d78f2d2abe942f88a3a4df9f8bb5e535ba;p=thirdparty%2Fhaproxy.git BUG/MINOR: config: use a copy of the file name in proxy configurations Each proxy contains a reference to the original config file and line number where it was declared. The pointer used is just a reference to the one passed to the function instead of being duplicated. The effect is that it is not valid anymore at the end of the parsing and that all proxies will be enumerated as coming from the same file on some late configuration errors. This may happen for exmaple when reporting SSL certificate issues. By copying using strdup(), we avoid this issue. 1.4 has the same issue, though no report of the proxy file name is done out of the config section. Anyway a backport is recommended to ease post-mortem analysis. --- diff --git a/include/types/proxy.h b/include/types/proxy.h index 641bc1c7ba..9bfa68def2 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -354,7 +354,7 @@ struct proxy { char *logformat_string; /* log format string */ char *uniqueid_format_string; /* unique-id format string */ struct { - const char *file; /* file where the section appears */ + char *file; /* file where the section appears */ int line; /* line where the section appears */ struct eb32_node id; /* place in the tree of used IDs */ struct eb_root used_listener_id;/* list of listener IDs in use */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 91b4b7f13f..bc9d93f867 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1242,7 +1242,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) curpeers->next = peers; peers = curpeers; - curpeers->conf.file = file; + curpeers->conf.file = strdup(file); curpeers->conf.line = linenum; curpeers->last_change = now.tv_sec; curpeers->id = strdup(args[1]); @@ -1279,7 +1279,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) newpeer->next = curpeers->remote; curpeers->remote = newpeer; newpeer->peers = curpeers; - newpeer->conf.file = file; + newpeer->conf.file = strdup(file); newpeer->conf.line = linenum; newpeer->last_change = now.tv_sec; @@ -1451,7 +1451,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) init_new_proxy(curproxy); curproxy->next = proxy; proxy = curproxy; - curproxy->conf.file = file; + curproxy->conf.file = strdup(file); curproxy->conf.line = linenum; curproxy->last_change = now.tv_sec; curproxy->id = strdup(args[1]); @@ -3913,7 +3913,7 @@ stats_error_parsing: newsrv->next = curproxy->srv; curproxy->srv = newsrv; newsrv->proxy = curproxy; - newsrv->conf.file = file; + newsrv->conf.file = strdup(file); newsrv->conf.line = linenum; LIST_INIT(&newsrv->actconns); diff --git a/src/haproxy.c b/src/haproxy.c index b9179f001e..8ac86cd769 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -852,6 +852,7 @@ void deinit(void) deinit_signals(); while (p) { + free(p->conf.file); free(p->id); free(p->check_req); free(p->cookie_name);