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.
This commit is contained in:
Willy Tarreau 2012-10-04 08:01:43 +02:00
parent d1a33e35fb
commit 8113a5d78f
3 changed files with 6 additions and 5 deletions

View File

@ -354,7 +354,7 @@ struct proxy {
char *logformat_string; /* log format string */ char *logformat_string; /* log format string */
char *uniqueid_format_string; /* unique-id format string */ char *uniqueid_format_string; /* unique-id format string */
struct { struct {
const char *file; /* file where the section appears */ char *file; /* file where the section appears */
int line; /* line where the section appears */ int line; /* line where the section appears */
struct eb32_node id; /* place in the tree of used IDs */ struct eb32_node id; /* place in the tree of used IDs */
struct eb_root used_listener_id;/* list of listener IDs in use */ struct eb_root used_listener_id;/* list of listener IDs in use */

View File

@ -1242,7 +1242,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
curpeers->next = peers; curpeers->next = peers;
peers = curpeers; peers = curpeers;
curpeers->conf.file = file; curpeers->conf.file = strdup(file);
curpeers->conf.line = linenum; curpeers->conf.line = linenum;
curpeers->last_change = now.tv_sec; curpeers->last_change = now.tv_sec;
curpeers->id = strdup(args[1]); 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; newpeer->next = curpeers->remote;
curpeers->remote = newpeer; curpeers->remote = newpeer;
newpeer->peers = curpeers; newpeer->peers = curpeers;
newpeer->conf.file = file; newpeer->conf.file = strdup(file);
newpeer->conf.line = linenum; newpeer->conf.line = linenum;
newpeer->last_change = now.tv_sec; 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); init_new_proxy(curproxy);
curproxy->next = proxy; curproxy->next = proxy;
proxy = curproxy; proxy = curproxy;
curproxy->conf.file = file; curproxy->conf.file = strdup(file);
curproxy->conf.line = linenum; curproxy->conf.line = linenum;
curproxy->last_change = now.tv_sec; curproxy->last_change = now.tv_sec;
curproxy->id = strdup(args[1]); curproxy->id = strdup(args[1]);
@ -3913,7 +3913,7 @@ stats_error_parsing:
newsrv->next = curproxy->srv; newsrv->next = curproxy->srv;
curproxy->srv = newsrv; curproxy->srv = newsrv;
newsrv->proxy = curproxy; newsrv->proxy = curproxy;
newsrv->conf.file = file; newsrv->conf.file = strdup(file);
newsrv->conf.line = linenum; newsrv->conf.line = linenum;
LIST_INIT(&newsrv->actconns); LIST_INIT(&newsrv->actconns);

View File

@ -852,6 +852,7 @@ void deinit(void)
deinit_signals(); deinit_signals();
while (p) { while (p) {
free(p->conf.file);
free(p->id); free(p->id);
free(p->check_req); free(p->check_req);
free(p->cookie_name); free(p->cookie_name);