]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log: Wrong log format initialization.
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 14 May 2019 08:57:58 +0000 (10:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 May 2019 09:12:00 +0000 (11:12 +0200)
This patch fixes an issue introduced by 0bad840b commit
"MINOR: log: Extract some code to send syslog messages" which leaded
to wrong log format variable initializations at least for "short" and "raw" format.
This commit skipped the cases where even if passed to __do_send_log(), the
syslog tag and syslog pid string must not be used to format the log message
with "short" and "raw". This is done iniatilizing "tag_max" and "pid_max"
variables (the lengths of the tag and pid strings) to 0, then updating to them to
the length of the tag and pid strings passed as variables to __do_send_log()
depending on the log format and in every cases using this length for the iovec
variable used to send() the log.

This bug is specific to 2.0.

src/log.c

index 7e14d89e2cb846c7443b960c7bbc3f6496b8fbe2..50553c6fbeb4e3b32aa3201a57ac2e13f9eb31a2 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1483,7 +1483,6 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
        time_t time = date.tv_sec;
        char *hdr, *hdr_ptr;
        size_t hdr_size;
-       struct buffer *tag = &global.log_tag;
        int fac_level;
        int *plogfd;
        char *pid_sep1 = "", *pid_sep2 = "";
@@ -1493,6 +1492,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
        int hdr_max = 0;
        int tag_max = 0;
        int pid_sep1_max = 0;
+       int pid_max = 0;
        int pid_sep2_max = 0;
        int sd_max = 0;
        int max = 0;
@@ -1605,7 +1605,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
        maxlen = logsrv->maxlen - hdr_max;
 
        /* tag */
-       tag_max = tag->data;
+       tag_max = tag_size;
        if (unlikely(tag_max >= maxlen)) {
                tag_max = maxlen - 1;
                sd_max = 0;
@@ -1626,6 +1626,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
        maxlen -= pid_sep1_max;
 
        /* pid */
+       pid_max = pid_size;
        if (unlikely(pid_size >= maxlen)) {
                pid_size = maxlen - 1;
                sd_max = 0;
@@ -1656,11 +1657,11 @@ send:
        iovec[0].iov_base = hdr_ptr;
        iovec[0].iov_len  = hdr_max;
        iovec[1].iov_base = tag_str;
-       iovec[1].iov_len  = tag_size;
+       iovec[1].iov_len  = tag_max;
        iovec[2].iov_base = pid_sep1;
        iovec[2].iov_len  = pid_sep1_max;
        iovec[3].iov_base = pid_str;
-       iovec[3].iov_len  = pid_size;
+       iovec[3].iov_len  = pid_max;
        iovec[4].iov_base = pid_sep2;
        iovec[4].iov_len  = pid_sep2_max;
        iovec[5].iov_base = sd;