]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: log: don't let an LF in a forwarded message create new events
authorGihyeon Ryu <rlgusryu@gmail.com>
Wed, 11 Nov 2026 10:00:12 +0000 (10:00 +0000)
committerOlivier Houchard <cognet@ci0.org>
Fri, 13 Nov 2026 15:55:27 +0000 (16:55 +0100)
A message received by a log-forward section over UDP or over TCP with
octet counting may contain CR or LF bytes. They are forwarded as is to
line-based outputs (rings, tcp@ servers, stdout/stderr), where each LF
starts a new event. A sender can then forge complete syslog lines with
any host name and program, which also defeats "option host".

syslog_process_message() now replaces every CR and LF but the trailing
ones with a space before parsing, so each received message gives one
line.

This should be backported to all stable branches.

src/log.c

index 7e2ee16ec03d9326ff3ee610fc546884658bcbfb..08681070b7704137baaa3abce5add6dffe6e3a84 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -6117,6 +6117,24 @@ bad_format:
        return;
 }
 
+/* Replace CR and LF with a space, except the trailing ones (already
+ * dropped by the send path), so a received message cannot create extra
+ * events on the outputs.
+ */
+static void syslog_flatten_message(struct buffer *buf)
+{
+       size_t len = buf->data;
+       size_t i;
+
+       while (len && (buf->area[len - 1] == '\n' || buf->area[len - 1] == 0))
+               len--;
+
+       for (i = 0; i < len; i++) {
+               if (buf->area[i] == '\n' || buf->area[i] == '\r')
+                       buf->area[i] = ' ';
+       }
+}
+
 /* helper function for syslog handlers: process input message sent by
  * <saddr> and stored in <buf> according to <frontend> options, and send
  * it to frontend loggers
@@ -6138,6 +6156,8 @@ static void syslog_process_message(struct proxy *frontend, struct listener *l,
        _HA_ATOMIC_INC(&cum_log_messages);
        proxy_inc_fe_req_ctr(l, frontend, 0);
 
+       syslog_flatten_message(buf);
+
        prepare_log_message(buf->area, buf->data, &level, &facility, metadata, &message, &size);
 
        if (frontend->options3 & PR_O3_DONTPARSELOG)