]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: config: use a copy of the file name in proxy configurations
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Oct 2012 06:01:43 +0000 (08:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 4 Oct 2012 06:13:32 +0000 (08:13 +0200)
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.

include/types/proxy.h
src/cfgparse.c
src/haproxy.c

index 641bc1c7ba742e70bb7b6a21b0030850d397857a..9bfa68def2e8ea279f6c0c15f2e317be2bfeccbd 100644 (file)
@@ -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 */
index 91b4b7f13f7ce55f25a31c9c7d199b55b412ea06..bc9d93f8671710624d19f8f86dc8384472fc6b79 100644 (file)
@@ -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);
index b9179f001e631eb810c4ba94da552929f55bcc03..8ac86cd769f81b659f350b8c729bbfd3023d61bb 100644 (file)
@@ -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);