]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: logs: prevent double line returns in some events.
authorEmeric Brun <ebrun@haproxy.com>
Tue, 12 May 2020 17:33:15 +0000 (19:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 19 May 2020 08:59:53 +0000 (10:59 +0200)
Historically some messages used to already contain the trailing LF but
not all, and __do_send_log adds a new one in needed cases. It also does
trim a trailing LF in certain cases while computing the max message
length, as a result of subtracting 1 to the available room in the
destination buffer. But the way it's done is wrong since some messages
still contain it.

So the code was fixed to always trim the trailing LF from messages if
present, and then only subtract 1 from the destination buffer room
instead of the size..

Note: new sink API is not designed to receive a trailing LF on
event messages

This could be backported to relevant stable versions with particular
care since the logic of the code changed a bit since 1.6 and there
may be other locations that need to be adjusted.

src/log.c

index 5d672942c8a6f0329d77a100530eea234f86adee..622f7f90e0bef7984b6766ec5ba7f2b15518049b 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1571,6 +1571,10 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
 
        dataptr = message;
 
+       /* historically some messages used to already contain the trailing LF */
+       if (size && (dataptr[size-1] == '\n'))
+               size--;
+
        if (logsrv->type == LOG_TARGET_FD) {
                /* the socket's address is a file descriptor */
                plogfd = (int *)&((struct sockaddr_in *)&logsrv->addr)->sin_addr.s_addr;
@@ -1625,7 +1629,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
                hdr_ptr = hdr;
                hdr_max = 3;
                maxlen = logsrv->maxlen - hdr_max;
-               max = MIN(size, maxlen) - 1;
+               max = MIN(size, maxlen - 1);
                goto send;
 
        case LOG_FORMAT_RAW:
@@ -1633,7 +1637,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
                hdr_ptr = hdr = "";
                hdr_max = 0;
                maxlen = logsrv->maxlen;
-               max = MIN(size, maxlen) - 1;
+               max = MIN(size, maxlen - 1);
                goto send;
 
        default:
@@ -1717,7 +1721,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
                goto send;
        }
 
-       max = MIN(size, maxlen - sd_max) - 1;
+       max = MIN(size, maxlen - sd_max - 1);
 send:
        if (logsrv->addr.ss_family == AF_UNSPEC) {
                /* the target is a file descriptor or a ring buffer */