]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Fix sending log lines when prefix is larger than PIPE_BUF
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 13 Aug 2020 19:18:41 +0000 (22:18 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 13 Aug 2020 20:42:06 +0000 (23:42 +0300)
This caused the log line to be sent repeatedly to the log process, possibly
causing hundreds of duplicate log lines.

src/lib/failures.c

index 9ce004938a0581e393d9295e555a830167423b00..8ac26269cdabe3efc949e3014ff98d6fa4dac269 100644 (file)
@@ -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);