From: Timo Sirainen Date: Thu, 13 Aug 2020 19:18:41 +0000 (+0300) Subject: lib: Fix sending log lines when prefix is larger than PIPE_BUF X-Git-Tag: 2.3.13~392 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=812fab2981d77e6edd6f70bd750ff2ddf88efdf7;p=thirdparty%2Fdovecot%2Fcore.git lib: Fix sending log lines when prefix is larger than PIPE_BUF This caused the log line to be sent repeatedly to the log process, possibly causing hundreds of duplicate log lines. --- diff --git a/src/lib/failures.c b/src/lib/failures.c index 9ce004938a..8ac26269cd 100644 --- a/src/lib/failures.c +++ b/src/lib/failures.c @@ -755,12 +755,30 @@ const char *i_get_failure_prefix(void) static int internal_send_split(string_t *full_str, size_t prefix_len) { + /* This function splits the log line into PIPE_BUF sized blocks, so + the log process doesn't see partial lines. The log prefix is + repeated for each sent line. However, if the log prefix is + excessively long, we're still going to send the log lines even + if they are longer than PIPE_BUF. LINE_MIN_TEXT_LEN controls the + minimum number of bytes we're going to send of the actual log line + regardless of the log prefix length. (Alternative solution could be + to just forcibly split the line to PIPE_BUF length blocks without + repeating the log prefix for subsequent lines.) */ +#define LINE_MIN_TEXT_LEN 128 +#if LINE_MIN_TEXT_LEN >= PIPE_BUF +# error LINE_MIN_TEXT_LEN too large +#endif string_t *str; size_t max_text_len, pos = prefix_len; str = t_str_new(PIPE_BUF); str_append_data(str, str_data(full_str), prefix_len); - max_text_len = PIPE_BUF - prefix_len - 1; + if (prefix_len < PIPE_BUF) { + max_text_len = I_MAX(PIPE_BUF - prefix_len - 1, + LINE_MIN_TEXT_LEN); + } else { + max_text_len = LINE_MIN_TEXT_LEN; + } while (pos < str_len(full_str)) { str_truncate(str, prefix_len);