mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-05 04:56:10 +02:00
BUG/MINOR: logs: prevent double line returns in some events.
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.
This commit is contained in:
parent
62f79fe68a
commit
9e8ea0ae6f
10
src/log.c
10
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 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user