BUG/MINOR: log: Wrong log format initialization.

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.
This commit is contained in:
Frdric Lcaille 2019-05-14 10:57:58 +02:00 committed by Willy Tarreau
parent 8bdb5c9bb4
commit 90a10aeb65

View File

@ -1483,7 +1483,6 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
time_t time = date.tv_sec; time_t time = date.tv_sec;
char *hdr, *hdr_ptr; char *hdr, *hdr_ptr;
size_t hdr_size; size_t hdr_size;
struct buffer *tag = &global.log_tag;
int fac_level; int fac_level;
int *plogfd; int *plogfd;
char *pid_sep1 = "", *pid_sep2 = ""; 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 hdr_max = 0;
int tag_max = 0; int tag_max = 0;
int pid_sep1_max = 0; int pid_sep1_max = 0;
int pid_max = 0;
int pid_sep2_max = 0; int pid_sep2_max = 0;
int sd_max = 0; int sd_max = 0;
int 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; maxlen = logsrv->maxlen - hdr_max;
/* tag */ /* tag */
tag_max = tag->data; tag_max = tag_size;
if (unlikely(tag_max >= maxlen)) { if (unlikely(tag_max >= maxlen)) {
tag_max = maxlen - 1; tag_max = maxlen - 1;
sd_max = 0; sd_max = 0;
@ -1626,6 +1626,7 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
maxlen -= pid_sep1_max; maxlen -= pid_sep1_max;
/* pid */ /* pid */
pid_max = pid_size;
if (unlikely(pid_size >= maxlen)) { if (unlikely(pid_size >= maxlen)) {
pid_size = maxlen - 1; pid_size = maxlen - 1;
sd_max = 0; sd_max = 0;
@ -1656,11 +1657,11 @@ send:
iovec[0].iov_base = hdr_ptr; iovec[0].iov_base = hdr_ptr;
iovec[0].iov_len = hdr_max; iovec[0].iov_len = hdr_max;
iovec[1].iov_base = tag_str; 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_base = pid_sep1;
iovec[2].iov_len = pid_sep1_max; iovec[2].iov_len = pid_sep1_max;
iovec[3].iov_base = pid_str; 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_base = pid_sep2;
iovec[4].iov_len = pid_sep2_max; iovec[4].iov_len = pid_sep2_max;
iovec[5].iov_base = sd; iovec[5].iov_base = sd;