BUG/MEDIUM: logs: segfault writing to log from Lua
Michael Ezzell reported a bug causing haproxy to segfault during startup
when trying to send syslog message from Lua. The function __send_log() can
be called with *p that is NULL and/or when the configuration is not fully
parsed, as is the case with Lua.
This patch fixes this problem by using individual vectors instead of the
pre-generated strings log_htp and log_htp_rfc5424.
Also, this patch fixes a problem causing haproxy to write the wrong pid in
the logs -- the log_htp(_rfc5424) strings were generated at the haproxy
start, but "pid" value would be changed after haproxy is started in
daemon/systemd mode.
diff --git a/src/haproxy.c b/src/haproxy.c
index ebc7177..c2768fc 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -626,7 +626,7 @@
progname = tmp + 1;
/* the process name is used for the logs only */
- global.log_tag = strdup(progname);
+ chunk_initstr(&global.log_tag, strdup(progname));
argc--; argv++;
while (argc > 0) {
@@ -1335,8 +1335,6 @@
LIST_DEL(&log->list);
free(log);
}
- chunk_destroy(&p->log_htp);
- chunk_destroy(&p->log_htp_rfc5424);
list_for_each_entry_safe(lf, lfb, &p->logformat, list) {
LIST_DEL(&lf->list);
@@ -1478,7 +1476,7 @@
#endif
free(global.log_send_hostname); global.log_send_hostname = NULL;
- free(global.log_tag); global.log_tag = NULL;
+ chunk_destroy(&global.log_tag);
free(global.chroot); global.chroot = NULL;
free(global.pidfile); global.pidfile = NULL;
free(global.node); global.node = NULL;